Reputation: 509
I am developing a windows phone application which requires to convert the current latitude and longitude into the address on the map. how to convert a Geo-coordinate to address pointing to the map using GoogleMaps.LocationServices Nu Get package.
Upvotes: 0
Views: 627
Reputation: 15296
GoogleMaps.LocationServices NuGet package doesn't have method to find street address. Try the below code.
const string API_ADDRESS_FROM_LATLONG = "http://maps.googleapis.com/maps/api/geocode/xml?latlng={0},{1}&sensor=false";
public void GetAddressFromLatLong(string Lat, string Long)
{
try
{
var webClient = new WebClient();
webClient.DownloadStringAsync(new Uri(string.Format(API_ADDRESS_FROM_LATLONG, Lat, Long)));
webClient.DownloadStringCompleted += webClient_DownloadStringCompleted;
}
catch (Exception)
{
}
}
void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
try
{
XDocument doc = XDocument.Parse(e.Result);
var Address = doc.Descendants("result").FirstOrDefault().Descendants("formatted_address").FirstOrDefault().Value;
MessageBox.Show(Address);
}
catch (Exception)
{
}
}
Upvotes: 1