How to find user's country

Cabtine Yassine picture Cabtine Yassine · Jan 5, 2015 · Viewed 7.6k times · Source

I am building a Cordova app for android platform.

I need to get the user's country.

I know that the geolocalisation gives the GPS coordinates.

Is there a way to have the country without using any external API? if not possible what is the best solution?

Answer

Ivan Gammel picture Ivan Gammel · Dec 18, 2016

There's important difference from UX and legal perspective on what country do you need:

  1. Country of current location: use geolocation API and any mapping solution. This is the only reliable way to determine country of location, since detection by IP or SIM card may only identify the country of telecom provider. Note, that country of the current location is not the country of citizenship and it does not allow to determine user's language or locale preferences.
  2. Country as the context for localization: use ECMAScript Internationalization API[1] and cordova-globalization-plugin[2] as a fallback. Note, that these APIs do not provide location information at all: language and locale information are not the same as user's country (e.g. user may choose french locale and en_US language, while living in Monaco and being a citizen of Russia).
  3. Country of citizenship. In some cases, it is a critical information for your service (e.g. when personal data of the user collected by the client-server system has to be physically processed in the country of citizenship as required by laws). The only way to determine it is to ask the user and require the honest answer from him by your Terms of Service. Note, that country of citizenship does not determine localization settings or user's current location.

[1] http://www.ecma-international.org/ecma-402/1.0/

[2] https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-globalization/