Get current country in Android - traveling

fersarr picture fersarr · Feb 17, 2014 · Viewed 14.5k times · Source

I'm making an app in which I assign different values to each country and do something based on that value. Like:

Argentina 3
Australia 7
USA 23

To choose the country, I need to use the user's current country, for that I'm using Google's geocoder:

geocoder.getFromLocation

Geocoder documentation

But if I have many users (hopefully), it will be a problem, because of the API usage restriction of 2500 (With/Without an API key: 2,500 requests per 24 hour period.)
Geocoder API Limits

Question 1: About the usage restriction, Is that number the maximum amount of requests for all the users using my map?

EDIT: I found this

As geocoding limits are per user session, there is no risk that your application will reach a global limit as your userbase grows. Client-side geocoding will not face a quota limit unless you perform a batch of geocoding requests within a user session. Therefore, running client-side geocoding, you generally don't have to worry about your quota. usage Limits

Question 2: Let's say I do use Geocoder.getFromLocation(), Is there a list of the country names that Google uses? For example, they could have "USA", "US" or "United States", or even "The United States of America". I need this is in order to access the country's value in the table above.

I'm thinking about initially obtaining the country using the typical ways:

telephonyManager.getSimCountryIso();

or

context.getResources().getConfiguration().locale.getCountry(); 

and adding a refresh button so the user can update it when traveling (using geocoder).

Question 3: Do you have any other suggestions? alternatives?

Answer

Gabe Sechan picture Gabe Sechan · Feb 17, 2014

For #2- its a country code. This is an ISO standard. It will be the 2 letter code. The list can be found here http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2