Error: sequence contains no elements

I got an error when I get lat and long using locationService.GetLatLongFromAddress

Error:

The sequence contains no elements.

I tried this code

var locationService = new GoogleLocationService();
var points = locationService.GetLatLongFromAddress("Ram Theatre Bus Stop, Arcot Road, Vadapalani, Chennai, Tamil Nadu");
mapDetail.Latitude = points.Latitude;
mapDetail.Longitude = points.Longitude;
mapDetail.CollegeAddressId = addressDetail[i].CollegeAddressId;

What is the problem? How can i solve this?

+4
source share
2 answers

, .First() .Single() (IEnumerable<T>), ( ): . : ( null). , , , .GetLatLongFromAddress(). , , , " " , , . , " " null - " " . , . : ( ).

: :

XDocument doc = XDocument.Load(string.Format(APIUrlLatLongFromAddress,
    Uri.EscapeDataString(address)));
var els = doc.Descendants("result").Descendants("geometry")
    .Descendants("location").First();
if (null != els) {...}

IMO, :

XDocument doc = XDocument.Load(string.Format(APIUrlLatLongFromAddress,
    Uri.EscapeDataString(address)));
var els = doc.Descendants("result").Descendants("geometry")
    .Descendants("location").FirstOrDefault();
if (null != els) {...}

, ...

+4

Mark Gravell pull GoogleLocationService Nuget.

https://www.nuget.org/packages/GoogleMaps.LocationServices/

+2

Source: https://habr.com/ru/post/1536776/


All Articles