Location problem


Last Updated:

  1. aminet73

    aminet73 Member This Topic's Starter

    Joined:
    Sep 25, 2009
    Messages:
    8
    Likes Received:
    0
    Hi,

    I've published an application on the android market. I've been using the Location Service for retrieving the user's country code that is used for highscores etc.

    The problem is that I only retrieve country codes from users which have the same nationality as me(Danish). In other words: I only get a small percentage of the users country code.

    Any suggestions for what I'm missing? I'm using the default locale. Does the export wizard build in some language specific stuff?

    Cheers
    Anders
     

    Advertisement
  2. KeithG

    KeithG Well-Known Member

    Joined:
    Nov 15, 2009
    Messages:
    103
    Likes Received:
    3
    How are you accessing the locale information? Something like this?

    String locale = context.getResources().getConfiguration().locale.getDisplayName();
     
  3. aminet73

    aminet73 Member This Topic's Starter

    Joined:
    Sep 25, 2009
    Messages:
    8
    Likes Received:
    0
    Here is the snippet that I'm using for setting up the location manager and geocoder:

    Code (Text):
    1. Geocoder geoCoder = new Geocoder(context.getBaseContext(), Locale
    2.                 .getDefault());
    3.        
    4. LocationManager locationManger = (LocationManager) context
    5.                 .getSystemService(Context.LOCATION_SERVICE);
    And the code for retrieving the country code:

    Code (Text):
    1. Criteria criteria = new Criteria();
    2. criteria.setAccuracy(Criteria.ACCURACY_COARSE);
    3. criteria.setCostAllowed(false);
    4. String provider = locationManager.getBestProvider(criteria,
    5.              true);
    6.  
    7. List<String> providers = locationManager.getProviders(false);
    8. String provider = null;
    9. if (!providers.isEmpty()) {
    10.          provider = providers.get(0);
    11. }
    12. if (provider != null) {
    13.     Location location = locationManager             .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
    14.                 if (location != null) {
    15.                     List<Address> fromLocation = geoCoder.getFromLocation(
    16.                             location.getLatitude(), location.getLongitude(), 3);
    17.  
    18.                     if (fromLocation != null) {
    19.                         for (Address address : fromLocation) {
    20.                             if (address.getCountryCode() != null) {
    21.                                 player.setCode(address.getCountryCode());
     

Share This Page

Loading...