gpt4 book ai didi

c# - 如何从 Windows Phone 8.1 获取当前国家/地区位置以及可能的国家/地区代码

转载 作者:行者123 更新时间:2023-11-30 16:54:33 24 4
gpt4 key购买 nike

如何从 Windows Phone 8.1 获取当前国家/地区位置以及可能的国家/地区代码?我这样做了,但 FindLocationsAsync 抛出异常“值不在预期范围内”

private async void LocateMe()
{
Geolocator GeoLoc = new Geolocator();
GeoLoc.DesiredAccuracyInMeters = 50;

try
{
Geoposition GeoPosition = await GeoLoc.GetGeopositionAsync();

MapLocationFinderResult result = await MapLocationFinder.FindLocationsAsync("", GeoPosition.Coordinate.Point, 5);

if (result.Status == MapLocationFinderStatus.Success)
{
foreach (MapLocation mapLocation in result.Locations)
{
string strCountryCode = mapLocation.Address.CountryCode;
}
}
}
catch(Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
}
}

最佳答案

它叫做反向地理定位试试这个

 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;

关于c# - 如何从 Windows Phone 8.1 获取当前国家/地区位置以及可能的国家/地区代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30375477/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com