我正在尝试从 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 字段为 null 时,它会抛出 NullReferenceException。据我所知,Windows 8 没有提供 CivicAddress 提供程序。我想检查 Windows Phone 8.1 是否属于这种情况。如果是,我如何获取/编写 CivicAddress 提供程序?
您将需要为此使用反向地理编码 - 更多信息at MSDN.
As for 窗口运行时例如你可以使用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;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)