1. Check out our companion app, Forums for Android! Download from Google Play

Location problem

Discussion in 'Application Development' started by aminet73, Jan 18, 2010.

  1. aminet73

    aminet73 Member
    Thread Starter
    5

    Sep 25, 2009
    8
    0
    5
    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
    46

    Nov 15, 2009
    103
    3
    46
    How are you accessing the locale information? Something like this?

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

    aminet73 Member
    Thread Starter
    5

    Sep 25, 2009
    8
    0
    5
    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...