get user location using javascript code example
Example 1: php get location of user
$PublicIP = $_SERVER['REMOTE_ADDR'];
$json = file_get_contents("http://ipinfo.io/$PublicIP/geo");
$json = json_decode($json, true);
$country = $json['country'];
$region = $json['region'];
$city = $json['city'];
Example 2: jquery get location of user
$("#find_btn").click(function () {
if ("geolocation" in navigator){
navigator.geolocation.getCurrentPosition(function(position){
$("#result").html("Found your location <br />Lat : "+position.coords.latitude+" </br>Lang :"+ position.coords.longitude);
});
}else{
console.log("Browser doesn't support geolocation!");
}
});