在 Windows Phone 8.1 上获取 CivicAddress [英] Getting CivicAddress on Windows Phone 8.1

查看:19
本文介绍了在 Windows Phone 8.1 上获取 CivicAddress的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to get the CivicAddress from a Geoposition in Windows Phone 8.1

我尝试使用以下代码:

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

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

抛出 NullReferenceException 作为 CivicAddress 字段为空.我知道没有为 Windows 8 提供 CivicAddress 提供程序.我想检查一下 Windows Phone 8.1 是否是这种情况,如果是这样,我如何获取/编写 CivicAddress 提供程序?

which throws NullReferenceException as the CivicAddress field is null. 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?

推荐答案

为此您需要使用 ReverseGeocoding - 一些更多信息 在 MSDN.

You will need to use ReverseGeocoding for this - some more information at MSDN.

对于 windows 运行时,您可以例如使用 MapLocationFinder.FindLocationsAtAsync 用于此目的:

As for windows runtime you can for example use MapLocationFinder.FindLocationsAtAsync for this purpose:

 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;

这篇关于在 Windows Phone 8.1 上获取 CivicAddress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆