How to get visitor’s location (i.e. country) using geolocation?

You can use my service, http://ipinfo.io, for this. It will give you the client IP, hostname, geolocation information (city, region, country, area code, zip code etc) and network owner. Here’s a simple example that logs the city and country: $.get(“https://ipinfo.io”, function(response) { console.log(response.city, response.country); }, “jsonp”); Here’s a more detailed JSFiddle example that also prints … Read more

android webview geolocation

JavaScript must be enabled in the WebView, using WebSettings.setJavaScriptEnabled(true); The app needs permission ACCESS_FINE_LOCATION The WebView must use a custom WebChromeClient which implements WebChromeClient.onGeolocationPermissionsShowPrompt(). This method is called by the WebView to obtain permission to disclose the user’s location to JavaScript. (In the case of the browser, we show a prompt to the user.) The … Read more

Where am I? – Get country

/** * Get ISO 3166-1 alpha-2 country code for this device (or null if not available) * @param context Context reference to get the TelephonyManager instance from * @return country code or null */ public static String getUserCountry(Context context) { try { final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); final String simCountry = tm.getSimCountryIso(); if (simCountry … Read more

How to get Latitude and Longitude of the mobile device in android?

Use the LocationManager. LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); double longitude = location.getLongitude(); double latitude = location.getLatitude(); The call to getLastKnownLocation() doesn’t block – which means it will return null if no position is currently available – so you probably want to have a look at passing a LocationListener to the requestLocationUpdates() method … Read more

Getting visitors country from their IP

Try this simple PHP function. <?php function ip_info($ip = NULL, $purpose = “location”, $deep_detect = TRUE) { $output = NULL; if (filter_var($ip, FILTER_VALIDATE_IP) === FALSE) { $ip = $_SERVER[“REMOTE_ADDR”]; if ($deep_detect) { if (filter_var(@$_SERVER[‘HTTP_X_FORWARDED_FOR’], FILTER_VALIDATE_IP)) $ip = $_SERVER[‘HTTP_X_FORWARDED_FOR’]; if (filter_var(@$_SERVER[‘HTTP_CLIENT_IP’], FILTER_VALIDATE_IP)) $ip = $_SERVER[‘HTTP_CLIENT_IP’]; } } $purpose = str_replace(array(“name”, “\n”, “\t”, ” “, “-“, “_”), … Read more

How to get current location in Android [duplicate]

First you need to define a LocationListener to handle location changes. int LOCATION_REFRESH_TIME = 15000; // 15 seconds to update int LOCATION_REFRESH_DISTANCE = 500; // 500 meters to update …. private final LocationListener mLocationListener = new LocationListener() { @Override public void onLocationChanged(final Location location) { //your code here } }; Then get the LocationManager and … Read more