Csharp/C#教程:在Windows Phone 8.1上获取CivicAddress分享


在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获得公民地址https://msdn.microsoft.com/en-us/library/system.device.location.civicaddress(v=vs.110).aspx

上述就是C#学习教程:在Windows Phone 8.1上获取CivicAddress分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1035034.html

(0)
上一篇 2022年1月19日
下一篇 2022年1月19日

精彩推荐