我正在开发一个 windows phone 应用程序,它需要将当前的纬度和经度转换为地图上的地址。如何使用 GoogleMaps.LocationServices Nu Get 包将地理坐标转换为指向地图的地址。
问问题
557 次
1 回答
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)
{
}
}
于 2013-10-30T10:46:43.970 回答