0
    Console.Write("Please enter the name of the location: ");
    string locationName = Console.ReadLine();
    var location = new GoogleLocationService();
    var point = location.GetLatLongFromAddress(locationName);

    double latUn = point.Latitude;
    double lngUn = point.Longitude;

    float lat = Convert.ToSingle(latUn);
    float lng = Convert.ToSingle(lngUn);

    var loc = location.GetRegionFromLatLong(latUn, lngUn).Name;

I am using the following code to find the coordinates of a certain location and store them into variables latUn and lngUn. The variable loc is used to get the exact name, but every time I try to return var loc, it gives me a nullReferenceException.

Michael Lee
  • 67
  • 2
  • 9
  • i think this is also work for you http://stackoverflow.com/questions/16274508/how-to-call-google-geocoding-service-from-c-sharp-code – mukesh kudi Nov 14 '16 at 13:45
  • 1
    Check if the result of `GetRegionFromLatLong()` is not null before trying to access the name. – stuartd Nov 14 '16 at 13:48
  • 1
    Have you debugged to see if point is null or not? It is possible for the api to not return anything: [See the code here](https://github.com/sethwebster/GoogleMaps.LocationServices/blob/master/GoogleMaps.LocationServices/GoogleLocationService.cs#L221) – Jared Beach Nov 14 '16 at 13:49

0 Answers0