×

Discussion Board

Results 1 to 15 of 15
  1. #1
    Regular Contributor
    Join Date
    Mar 2013
    Posts
    65

    Question Easiest way to get user's country?

    What's the easiest way to get the country a user is in when they are running my app? Note I just need the country, not city or zip code.

    -- roschler

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,693

    Re: Easiest way to get user's country?

    If you have a server somewhere, connecting to it and checking the IP address can be a way.

  3. #3
    Nokia Developer Champion
    Join Date
    Feb 2013
    Location
    Dublin, Ireland
    Posts
    552

    Re: Easiest way to get user's country?

    WP8 does have a ReverseGeocodeQuery which is part of the Maps API...

    http://blogs.msdn.com/b/jrspinella/a...s-phone-8.aspx

    It does try to return a full address for the current position, but Country is part of it.

    http://msdn.microsoft.com/en-us/libr...v=vs.105).aspx

  4. #4
    Regular Contributor
    Join Date
    Jan 2009
    Location
    India
    Posts
    138

    Re: Easiest way to get user's country?

    Hi Roschler,

    You can use the following code snippet, to get the User Phone's current country.

    Code:
     public static string GetCurrentRegionOrCountry()
            {
                return Country = System.Globalization.RegionInfo.CurrentRegion.DisplayName;
            }
    Hope it helps
    Pavan Pareta
    Sr. Software Engineer
    http://windows-mobile-dev.blogspot.com

  5. #5
    Nokia Developer Champion
    Join Date
    Feb 2013
    Location
    Dublin, Ireland
    Posts
    552

    Re: Easiest way to get user's country?

    Quote Originally Posted by pavan.pareta View Post
    You can use the following code snippet, to get the User Phone's current country.
    That returns the country from the Region Settings of the phone, not the country the user is currently in.

  6. #6
    Regular Contributor
    Join Date
    Mar 2013
    Posts
    65

    Re: Easiest way to get user's country?

    Thanks @Pavan and everyone else. That's just what I needed.

    Funny, I'm not getting forum notifications in my E-mail when replies are posted.

    -- roschler

  7. #7
    Regular Contributor
    Join Date
    Mar 2013
    Posts
    65

    Re: Easiest way to get user's country?

    Good point but it's close enough for my needs.

  8. #8
    Regular Contributor
    Join Date
    Mar 2013
    Posts
    65

    Re: Easiest way to get user's country?

    @Pavan,

    Do you know where I can get a complete list of the countries returned by that call, exact spelling? I'm going to write code that string matches against the country so I need the right spellings.

  9. #9
    Regular Contributor
    Join Date
    Mar 2013
    Posts
    65

    Re: Easiest way to get user's country?

    @theothernt - Thanks for the the tip.

  10. #10
    Regular Contributor
    Join Date
    Mar 2013
    Posts
    65

    Question Get compelte list of countries returned by CurrentRegion.DisplayName?

    Can anyone point me to a complete list of country names returned by System.Globalization.RegionInfo.CurrentRegion.DisplayName (thanks Pavan). I need the complete list with exact spellings for code in my app that will match against elements in that list.

    Also, where do I find the exact Setting in my Lumia 520 phone that affects the value returned by System.Globalization.RegionInfo.CurrentRegion.DisplayName? I'll want to change that to different values to test my Country based code.

  11. #11
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,693

    Re: Get compelte list of countries returned by CurrentRegion.DisplayName?

    I would have a look at RegionInfo, http://msdn.microsoft.com/en-us/libr...v=vs.105).aspx and consider using TwoLetterISORegionName instead. Then just check the ISO 3166 standard. While iso.org wants money from you, the Wikipedia article http://en.wikipedia.org/wiki/ISO_3166 reveals that the 2-letter variants are actually the country-specific top level domain codes, and those are present in Wikipedia, http://en.wikipedia.org/wiki/List_of...-level_domains (and the listing also states that it is ISO 3166).
    Just remember that it will not tell you the country where the user is running your app. For example I am in Norway, but my phone is set to Hungarian.

  12. #12
    Regular Contributor
    Join Date
    Mar 2013
    Posts
    65

    Re: Get compelte list of countries returned by CurrentRegion.DisplayName?

    Thanks @wizard_hu. Good tip about the user's location vs. the user's region setting, but I just need something that's "mostly right". To go the full nine yards and do reverse geo-coding or get something like the MaxMind IP address database is overkill for my needs, and a lot more work.

  13. #13
    Regular Contributor
    Join Date
    Mar 2013
    Posts
    65

    Re: Get compelte list of countries returned by CurrentRegion.DisplayName?

    I found this list of top-level domain/region name pairs that is easy to integrate into a C# program. Posting it here in case it helps others. Look for the CSV download link at the bottom of the page:

    http://codehill.com/2009/09/a-list-o...level-domains/

  14. #14
    Nokia Developer Champion
    Join Date
    Sep 2012
    Location
    Morocco
    Posts
    296

    Re: Get compelte list of countries returned by CurrentRegion.DisplayName?

    Quote Originally Posted by roschler View Post
    Can anyone point me to a complete list of country names returned by System.Globalization.RegionInfo.CurrentRegion.DisplayName (thanks Pavan). I need the complete list with exact spellings for code in my app that will match against elements in that list.

    Also, where do I find the exact Setting in my Lumia 520 phone that affects the value returned by System.Globalization.RegionInfo.CurrentRegion.DisplayName? I'll want to change that to different values to test my Country based code.
    Hello,
    According to this link http://msdn.microsoft.com/en-us/libr...v=vs.110).aspx
    For the current list of RegionInfo names, see English country names and code elements on the ISO website.
    http://www.iso.org/iso/country_codes...e_elements.htm
    wizard_hu_ suggestion using IP addresses was good and more accurate than using Culture.lnfo (if your app works online)
    maybe if you tell us what you're trying to achieve we can figure out a better approach
    Yassine

  15. #15
    Regular Contributor
    Join Date
    Mar 2013
    Posts
    65

    Re: Get compelte list of countries returned by CurrentRegion.DisplayName?

    Hello Loukt,

    The country code/region solution is fine for my needs. Thanks for asking.

Similar Threads

  1. City and Country - User Profile
    By antonio5982 in forum Mobile Java General
    Replies: 7
    Last Post: 2009-02-13, 12:23
  2. How to get the country code or country name
    By gpalvia in forum Symbian User Interface
    Replies: 1
    Last Post: 2008-02-26, 18:18
  3. Replies: 3
    Last Post: 2007-12-01, 13:23
  4. Looking for The Easiest Way?
    By moja_a in forum Symbian Tools & SDKs
    Replies: 1
    Last Post: 2006-05-08, 08:51
  5. Easiest SMS integration
    By markci in forum General Messaging
    Replies: 1
    Last Post: 2002-11-11, 11:26

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×