获取CivicAddress在Windows Phone 8.1 [英] Getting CivicAddress on Windows Phone 8.1
问题描述
我想从可以将GeoPosition的CivicAddress中的Windows Phone 8.1
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字段为空。据我所知,CivicAddress提供商不提供针对Windows 8。我想检查这是否是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;
这篇关于获取CivicAddress在Windows Phone 8.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!