Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从Windows Phone 8.1获取当前国家/地区位置以及可能的国家/地区代码_C#_.net_Geolocation_Windows Phone 8.1_Windows 8.1 - Fatal编程技术网

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

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

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


这就是所谓的反向地理定位

 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;