简体   繁体   English

在Windows Phone 8.1上获取CivicAddress

[英]Getting CivicAddress on Windows Phone 8.1

I'm trying to get the CivicAddress from a Geoposition in Windows Phone 8.1 我正试图从Windows Phone 8.1中的Geoposition获取CivicAddress

I've tried using the following code: 我尝试使用以下代码:

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

// Get Country
var country = position.CivicAddress.Country;

which throws NullReferenceException as the CivicAddress field is null. 由于CivicAddress字段为null,因此抛出NullReferenceException。 I understand that a CivicAddress provider is not provided for Windows 8. I would like to check whether this is the case for Windows Phone 8.1 If so, how can I obtain / write a CivicAddress provider? 我知道没有为Windows 8提供CivicAddress提供程序。我想检查是否是Windows Phone 8.1的情况。如果是这样,我如何获取/编写CivicAddress提供程序?

You will need to use ReverseGeocoding for this - some more information at MSDN . 您需要使用ReverseGeocoding - MSDN上的更多信息。

As for windows runtime you can for example use MapLocationFinder.FindLocationsAtAsync for this purpose: 至于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;

If you want to get address for a position, then I would suggest you use ReverseGeocodeQuery API with the position you get with the Geolocator API, for reference implementation I do have an example available at github here https://github.com/nokia-developer/maps-samples/tree/master/RevGeoCoding 如果你想获得一个职位的地址,那么我建议你使用ReverseGeocodeQuery API和你在Geolocator API上获得的位置,参考实现我在github上有一个例子可以在https://github.com/nokia-找到显影剂/ MAPS-样本/树/主/ RevGeoCoding

else you could also try this to get civic address from GeoCoordinates http://msdn.microsoft.com/en-us/library/system.device.location.civicaddress(v=vs.110).aspx 否则你也可以尝试从GeoCoordinates获得公民地址http://msdn.microsoft.com/en-us/library/system.device.location.civicaddress(v=vs.110).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM