In my PHP based application i would like to capture the location of user machine when user logs in to the webapp based on IP address.
I followed this method:
$url = "http://freegeoip.net/json/$ip";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$data = curl_exec($ch);
curl_close($ch);
i am getting the latitude and longitude values but these are not exact, instead they are absolute. In the response i am getting JSON like this:
{
["ip"]=> string(11) "59.90.210.9"
["country_code"]=> string(2) "IN"
["country_name"]=> string(5) "India"
["region_code"]=> string(0) ""
["region_name"]=> string(0) ""
["city"]=> string(0) ""
["zip_code"]=> string(0) ""
["time_zone"]=> string(12) "Asia/Kolkata"
["latitude"]=> int(20)
["longitude"]=> int(77)
["metro_code"]=> int(0)
}
No city no zip nothing. Is there any better API to get exact things as required? Thanks in advance for any response.