我正在尝试从 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/