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;
}

Please check this code its fack
Hi Nilesh,
The code is right but the site (www.ipinfodb.com) has changed the api to get the latitude and longitude use the following code now on
$sXML = @file_get_contents(’http://api.ipinfodb.com/v2/ip_query.php?key=your_api_key&ip=’.$ip);
for the above code you will have to register with the site. There you will get an api key. Replace ‘your_api_key’ with the api key you get.
Hope it will work fine now. If you get any problem get back to me
.