2012-12-05 64 views
1

可能重复:
How to get Address name of GPS coordinate with wp7位置细节的Windows Phone 8

我developoing一个WP8 application.In我的应用程序,我想获得一个特定的位置一样的细节地理名称来自其地理坐标。我可以获得设备当前的GPS位置。但它只提供地理坐标。有没有提供地理坐标位置详细信息的服务?请帮帮我。

+1

[如何获取GPS坐标的地址名称与wp7](http://stackoverflow.com/questions/9294474/how-to-get-address-name-of-gps-coordinate-with-wp7) –

+0

这不是重复的。上一个问题针对的是WP7,WP8提供了一种新的和改进的反向地理编码查找方式。请参阅下面的@JustinAngels回答。 –

回答

6

你在找什么叫做反向地理编码。将Geocoordinate转换为地址。

如前所述,您可以在WP7上使用Google和Bing来实现这一点。在windows phone 8上,Geocoding和Reverse Geocoding作为框架的一部分得到了支持。您可以阅读GeoCoding at this Nokia intro article(在“地理编码”下)和更全面的概述at this other Nokia article的概述。

这里的反向地理编码从一个坐标地址转换的例子:

private void Maps_ReverseGeoCoding(object sender, RoutedEventArgs e) 
{ 
    ReverseGeocodeQuery query = new ReverseGeocodeQuery() 
    { 
     GeoCoordinate = new GeoCoordinate(37.7951799798757, -122.393819969147) 
    }; 
    query.QueryCompleted += query_QueryCompleted; 
    query.QueryAsync(); 
} 

void query_QueryCompleted(object sender, QueryCompletedEventArgs<IList<MapLocation>> e) 
{ 
    StringBuilder sb = new StringBuilder(); 
    sb.AppendLine("Ferry Building Geocoding results..."); 
    foreach (var item in e.Result) 
    { 
     sb.AppendLine(item.GeoCoordinate.ToString()); 
     sb.AppendLine(item.Information.Name); 
     sb.AppendLine(item.Information.Description); 
     sb.AppendLine(item.Information.Address.BuildingFloor); 
     sb.AppendLine(item.Information.Address.BuildingName); 
     sb.AppendLine(item.Information.Address.BuildingRoom); 
     sb.AppendLine(item.Information.Address.BuildingZone); 
     sb.AppendLine(item.Information.Address.City); 
     sb.AppendLine(item.Information.Address.Continent); 
     sb.AppendLine(item.Information.Address.Country); 
     sb.AppendLine(item.Information.Address.CountryCode); 
     sb.AppendLine(item.Information.Address.County); 
     sb.AppendLine(item.Information.Address.District); 
     sb.AppendLine(item.Information.Address.HouseNumber); 
     sb.AppendLine(item.Information.Address.Neighborhood); 
     sb.AppendLine(item.Information.Address.PostalCode); 
     sb.AppendLine(item.Information.Address.Province); 
     sb.AppendLine(item.Information.Address.State); 
     sb.AppendLine(item.Information.Address.StateCode); 
     sb.AppendLine(item.Information.Address.Street); 
     sb.AppendLine(item.Information.Address.Township); 
    } 
    MessageBox.Show(sb.ToString()); 
} 

当我跑我的WP8此代码段出现以下消息框:

MEssageBox showing details for the ferry building

+0

我收到语句'query.QueryAsync();'异常'System.UnauthorizedAccessException'和'System.Reflection.TargetInvocationException'。这可能是什么原因造成的? – Mayank

+0

@Mayank检查您的应用是否拨打多个电话,一次只能拨打一个电话,希望它有帮助 –