how to get current device location country name ?

Unanswered how to get current device location country name ?

  • Monday, April 23, 2012 9:28 AM
     
     
    Hi

    I'm developing an application where , i need to detect country name according to device location

    for example, 

    if user from uk download my app from marketplace then.. i need to detect country as UK in code
                     if someone from usa download my app then, i need to detect country as usa in code

     
    that way i will show different helpline phone no according to country

    Thanks in advance


All Replies

  • Monday, April 23, 2012 10:29 AM
     
     
    Hi,

    You may find the following useful :-

    http://stackoverflow.com/questions/5223295/detecting-home-country-of-windows-phone-7

    Hope this helps.

    Paul Diston
  • Monday, April 23, 2012 12:14 PM
     
     
    Hi,
    you can use bing geocodeservice for retrieving country Region from current location..

    1st you need to find the current location then you call the service to find country Region..here I'm writing some code ..


    1.For find the current location


      GeoCoordinate location = null;
     

       GeoCoordinateWatcher   watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
       watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);
       watcher.Start();

    void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
            {
              
                if (watcher != null)
                {
                   
                    watcher.Stop();
                    watcher.Dispose();
                    watcher = null;

                    location = e.Position.Location;
                    ObtainCountry();//by this funtion you obtain country region
                }
            }

    2. for call the service and find the country region..
    public void ObtainCountry()
            {
                if (location == null)
                    return;

                ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest();

                // Set the credentials using a valid Bing Maps key
                reverseGeocodeRequest.Credentials = new BingService.Credentials();
                reverseGeocodeRequest.Credentials.ApplicationId = "your bing application id";

                // Set the point to use to find a matching address
                BingService.Location point = new BingService.Location();
                point.Latitude = location.Latitude;
                point.Longitude = location.Longitude;

                reverseGeocodeRequest.Location = point;

                // Make the reverse geocode request
                GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
                geocodeService.ReverseGeocodeCompleted += new EventHandler<ReverseGeocodeCompletedEventArgs>(geocodeService_ReverseGeocodeCompleted);
                geocodeService.ReverseGeocodeAsync(reverseGeocodeRequest);
            }

    void geocodeService_ReverseGeocodeCompleted(object sender, ReverseGeocodeCompletedEventArgs e)
            {
              
     string countryRegion = e.Result.Results[0].Address.CountryRegion;
               
            }



  • Monday, April 23, 2012 2:59 PM
     
     
    I don't believe that you can read which marketplace an application was installed from.

    The System.Globalization.CultureInfo.CurrentUICulture.* and System.Globalization.CulutreInfo.CurrentCulture.* methods are available, but you can hit cases like me where I have my culture set to different settings at different times.

    You can use LocationServices to try and figure out which country a person is in.

    You can look at the mobile provider information to try and determine where the user is from.

    Any of the first three methods you can use to set a default user setting for their help number, but it might be useful to allow the to set their location somewhere in the application as there are no guarantees that it would be the number they are looking for.