Phonegap is the best way to find out the ISO code of a country from a user

What is the best and fastest way to get an iso country code by starting an application build using a phone screen saver? There is a function that allows you to get geo, but not Iso code. To get the iso code, you may need to call an external web service and get iso by the given coordinates. The easiest way?

Thanks Nik

+3
source share
2 answers

Are you looking for where the user is currently located or something more than user language / nationality? For the latter, you can always see that in navigator.language. Depending on the target platform, it will give you either a language code ("en" on my Android test machine) or a language code and country code ("en-us" on my iOS test machine). To find out what he will give you, go to your device’s browser browser here and enter navigator.languagein the text input field.

Otherwise, a random look at the HTML5 Geolocation specification indicates that you need a web service or a batch data file with codes in the application. That seems pretty good.

0
source

, navigator.language , (, "en", "en-gb" ). android, java src/com DeviceCulture.java :

package com;
import java.util.Locale;

public class DeviceCulture {

    public String get() {
        try{            
            return Locale.getDefault().toString();//get the locale from the Android Device      
        }catch(Exception e){
            return "";
        }   
    }
}

super.loadUrl /src/com/phonegap/YOUR _APP/App.java

DeviceCulture deviceCulture = new DeviceCulture();
appView.addJavascriptInterface(deviceCulture , "DeviceCulture");

javascript , (, "en_GB" )

window.DeviceCulture.get();
+1

Source: https://habr.com/ru/post/1783087/


All Articles