C# 如何从Windows Phone 8.1获取当前国家/地区位置以及可能的国家/地区代码
如何从Windows Phone 8.1获取当前国家/地区位置以及可能的国家/地区代码?我这样做了,但是FindLocationAsync抛出了一个异常“值不在预期范围内”C# 如何从Windows Phone 8.1获取当前国家/地区位置以及可能的国家/地区代码,c#,.net,geolocation,windows-phone-8.1,windows-8.1,C#,.net,Geolocation,Windows Phone 8.1,Windows 8.1,如何从Windows Phone 8.1获取当前国家/地区位置以及可能的国家/地区代码?我这样做了,但是FindLocationAsync抛出了一个异常“值不在预期范围内” 这就是所谓的反向地理定位 var geolocator = new Geolocator(); geolocator.DesiredAccuracyInMeters = 100; Geoposition position = await geolocator.GetGeopo
这就是所谓的反向地理定位
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.Region;
你应该试试这个。。我宣布Map_事件 私有异步无效
private async void mapNearByUser\u mapptapped(Windows.UI.Xaml.Controls.Maps.MapControl发送方,Windows.UI.Xaml.Controls.Maps.MapInputEventArgs args args)
{
//你的地图被点击了
Geopoint pointToReverseGeocode=新的地质点(参数位置位置);
//对指定的地理位置进行反向地理编码。
MapLocationFinderResult结果=
等待MapLocationFinder.FindLocationStatasync(指针反向代码);
var resultText=新的StringBuilder();
尝试
{
if(result.Status==MapLocationFinderStatus.Success)
{
resultText.AppendLine(result.Locations[0].Address.District+“,“+result.Locations[0].Address.Town+”,“+result.Locations[0].Address.Country);
}
MessageBox(resultText.ToString());
}
抓住
{
//MessageBox(resultText.ToString());
MessageBox(“请稍候…”);
}
}
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.Region;