本文介绍了从 Windows Phone 8 获取国家/地区名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有截图

我打算检索应该是尼日利亚"的国家.通过 System.Globalization 类后,我找到了下面的代码片段

and I am intending to retrieve the country which should be "Nigeria". After going through the System.Globalization class, I found the code snippet below

System.Globalization.RegionInfo.CurrentRegion.EnglishName

但我得到了美国",这是上图中的区域格式".有没有办法检索国家/地区值设置?

But I am getting "United States", which is the "Regional Format" from the image above. Is there no way i can retrieve the Country/Region value settings?

推荐答案

这就是我在一天结束时所做的.首先我使用Location API库来获取位置的坐标(经度和纬度)

This is what i did at the end of the day. First I used the Location API library to get the coordinates(longitude and latitude) of the location

        Geolocator geolocator = new Geolocator();
        geolocator.DesiredAccuracyInMeters = 50;

        try
        {
            // Request the current position
            Geoposition geoposition = await geolocator.GetGeopositionAsync(
                maximumAge: TimeSpan.FromMinutes(5),
                timeout: TimeSpan.FromSeconds(10)
            );

            string latitude = geoposition.Coordinate.Latitude.ToString("0.00");
            string longitude = geoposition.Coordinate.Longitude.ToString("0.00");


        }
        catch (Exception ex)
        {
            if ((uint)ex.HResult == 0x80004004)
            {
                // the application does not have the right capability or the location master switch is off
                MessageBox.Show("Location is disabled in phone settings.", "Can't Detect Location", MessageBoxButton.OK);

            }
            //else
            {
                // something else happened acquring the location
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }

然后使用google的反向地理定位,根据经纬度获取位置的信息或详细信息

then using google's reverse geolocation to get the information or details of the location based on the longitude and latitude

http://maps.googleapis.com/maps/api/geocode/json?latlng=latitiude,longitude&sensor=true

即如果纬度是 60,经度是 60

i.e if the latitude is 60 and the longitude is 60

http://maps.googleapis.com/maps/api/geocode/json?latlng=60,60&sensor=true

从json结果中,您将能够检索国家/地区的长短名称.

From the json result, you will be able to retrieve the country's long and short name.

这篇关于从 Windows Phone 8 获取国家/地区名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 16:08