我正在开发一个Windows Phone应用程序,它需要将当前纬度和经度转换为地图上的地址。 如何使用GoogleMaps.LocationServices Nu Get包将Geo坐标转换为指向地图的地址。
答案 0 :(得分:1)
GoogleMaps.LocationServices NuGet包没有查找街道地址的方法。请尝试以下代码。
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)
{
}
}