在Windows Phone 8.1上获取CivicAddress

我正试图从Windows Phone 8.1中的Geoposition获取CivicAddress

我尝试使用以下代码:

// Get Current Location var geolocator = new Geolocator(); geolocator.DesiredAccuracyInMeters = 100; var position = await geolocator.GetGeopositionAsync(); // Get Country var country = position.CivicAddress.Country; 

由于CivicAddress字段为null,因此抛出NullReferenceException。 我知道没有为Windows 8提供CivicAddress提供程序。我想检查是否是Windows Phone 8.1的情况。如果是这样,我如何获取/编写CivicAddress提供程序?

您将需要使用ReverseGeocoding – MSDN上的更多信息。

至于Windows运行时,您可以为此目的使用MapLocationFinder.FindLocationsAtAsync :

  var geolocator = new Geolocator(); geolocator.DesiredAccuracyInMeters = 100; Geoposition position = await geolocator.GetGeopositionAsync(); // reverse geocoding BasicGeoposition myLocation = new BasicGeoposition { Longitude = position.Coordinate.Longitude, Latitude = position.Coordinate.Latitude }; Geopoint pointToReverseGeocode = new Geopoint(myLocation); MapLocationFinderResult result = await MapLocationFinder.FindLocationsAtAsync(pointToReverseGeocode); // here also it should be checked if there result isn't null and what to do in such a case string country = result.Locations[0].Address.Country; 

如果你想获得一个职位的地址,那么我建议你使用ReverseGeocodeQuery API和你在Geolocator API上获得的位置,参考实现我在github上有一个例子可以在https://github.com/nokia-找到显影剂/ MAPS-样本/树/主/ RevGeoCoding

否则你也可以尝试这个从GeoCoordinates获得公民地址http://msdn.microsoft.com/en-us/library/system.device.location.civicaddress(v=vs.110).aspx