Get Country/Region name from windows phone 8

前端 未结 5 1624
日久生厌
日久生厌 2020-12-11 03:49

I have the screenshot

\"enter

and I am intending to retrieve the country which

相关标签:
5条回答
  • 2020-12-11 03:56

    Try this

    System.Globalization.RegionInfo.CurrentRegion.DisplayName;
    
    0 讨论(0)
  • 2020-12-11 04:04

    Use System.Threading.Thread.CurrentThread.CurrentCulture. It should correctly reflect the phone language.

    0 讨论(0)
  • 2020-12-11 04:09

    I know it's old, but maybe someone comes here looking for answer:

    System.Globalization.RegionInfo.CurrentRegion.TwoLetterISORegionName
    
    0 讨论(0)
  • 2020-12-11 04:11

    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);
                }
            }
    

    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
    

    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
    

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

    0 讨论(0)
  • 2020-12-11 04:19

    The correct answer to what the user is asking is this:

    Windows.System.UserProfile.GlobalizationPreferences.HomeGeographicRegion
    

    This should give you information regarding the Country/Region selection in the language+region setting.

    0 讨论(0)
提交回复
热议问题