Jul
Mapping The IP Address to Latitude and Longitude In Google Maps
Filed Under (Google Maps, PHP) by Subesh Pokhrel on 11-07-2008
Tagged Under : Google Maps, ip, latitude, longitude, PHP
At last I found hostip.info provides a service for getting the latitude and longitude of a place on the basis of the user’s ip address. Its light weight and free, rather than downloading bulky database and getting paid services, for getting latitude and longitude on the basis of IP.
Here is the simplest way to do it. Requested to http://api.hostip.info/?ip=$ip&position=true it responds XML formatted output. So we need to parse XML code using DOM class of PHP.(#19-#23). Remember, the position=true should be set to get the latitude and longitude otherwise it will not show on default.
Here is the code and I will soon upload the working demo.
[sourcecode=”php”]
/*
Subesh Pokhrel
subesh.com.np
Get the code for Real IP of the site from roshanbh.com.np
Mapping The IP Address to Latitude and Longitude.
*/
function IPtoLatLng($ip)
{
$latlngValue=array();
$dom = new DOMDocument();
$ipcheck = ip2long($ip); Read the rest of this entry »
![[del.icio.us]](http://subesh.com.np/wp-content/plugins/bookmarkify/delicious.png)
![[Digg]](http://subesh.com.np/wp-content/plugins/bookmarkify/digg.png)
![[Facebook]](http://subesh.com.np/wp-content/plugins/bookmarkify/facebook.png)
![[Google]](http://subesh.com.np/wp-content/plugins/bookmarkify/google.png)
![[MySpace]](http://subesh.com.np/wp-content/plugins/bookmarkify/myspace.png)
![[StumbleUpon]](http://subesh.com.np/wp-content/plugins/bookmarkify/stumbleupon.png)
![[Technorati]](http://subesh.com.np/wp-content/plugins/bookmarkify/technorati.png)
![[Windows Live]](http://subesh.com.np/wp-content/plugins/bookmarkify/windowslive.png)
![[Yahoo!]](http://subesh.com.np/wp-content/plugins/bookmarkify/yahoo.png)

