Post your trick

How to get Latitude and Longitude from IP address

After searching for more than four to five hours i got the link which give latitude, longitude and other information such as address including city and country. So here is a small function which will give you latitude and longitude of the given ip address.

function getLatLng($ip){

//get the contents from the site by file_get_contents.
$sXML = @file_get_contents(’http://ipinfodb.com/ip_query.php?ip=’.$ip.’&timezone=false’);

//make the response in a xml object so we can parse it.
$oXML = @new SimpleXMLElement($sXML);

$array = array(
‘Latitude’ => (string) $oXML->Latitude[0],
‘Longitude’ => (string) $oXML->Longitude[0]
);
return $array;
}


Post A Trick !

How does "Kodetricks" work?

We at kodeplay like to share knowledge. With Kodetricks, even you can join us. All you need to do is post a programming related trick if you have one or rate a trick if you like someone else's.



Technology

Contact Us