c# - 在 Windows Phone 8.1 上获取 CivicAddress

标签 c# windows-phone-8 geolocation windows-runtime windows-phone-8.1

我正在尝试从 Windows Phone 8.1 中的地理位置获取 CivicAddress

我试过使用下面的代码:

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

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

当 CivicAddress 字段为空时抛出 NullReferenceException。我了解 Windows 8 未提供 CivicAddress 提供程序。我想检查 Windows Phone 8.1 是否属于这种情况。如果是,我如何获取/编写 CivicAddress 提供程序?

最佳答案

您将需要为此使用 ReverseGeocoding - 更多信息 at MSDN .

至于windows runtime 你可以使用例如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;

关于c# - 在 Windows Phone 8.1 上获取 CivicAddress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23692120/

相关文章:

c# - 如何在 Windows Phone 8 中执行动画

c# - 如何在 C# 中使用 HttpClient 获取所有重定向 URL 的列表

c# - C#中如何动态调用方法?

c# - Caliburn.Micro 在 App.xaml 的命名空间中没有 "Bootstrapper"

c# - 启动 Storyboard时未设置目标错误

c# - 广告在 WP 应用程序中不起作用

java - 集合中的搜索/查询 (Java)

android - 计算两个位置之间的方位角(纬度、经度)

android - 为什么 google place api 给我的结果为零?

c# - session变量赋值给数据表和创建对象引用问题?