<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Subesh Pokhrel&#039;s Blog - Magento Development Tips &#187; ip</title>
	<atom:link href="http://subesh.com.np/tag/ip/feed/" rel="self" type="application/rss+xml" />
	<link>http://subesh.com.np</link>
	<description>PHP &#38; Magento Tips and Tutorials</description>
	<lastBuildDate>Wed, 01 Feb 2012 04:09:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Mapping The IP Address to Latitude and Longitude In Google Maps</title>
		<link>http://subesh.com.np/2008/07/mapping-the-ip-address-to-latitude-and-longitude-in-google-maps/</link>
		<comments>http://subesh.com.np/2008/07/mapping-the-ip-address-to-latitude-and-longitude-in-google-maps/#comments</comments>
		<pubDate>Fri, 11 Jul 2008 13:03:32 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ip]]></category>
		<category><![CDATA[latitude]]></category>
		<category><![CDATA[longitude]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=63</guid>
		<description><![CDATA[At last I found hostip.info provides a service for getting the latitude and longitude of a place on the basis of the user&#8217;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 [...]]]></description>
			<content:encoded><![CDATA[<p>At last I found <strong>hostip.info</strong> provides a service for getting the latitude and longitude of a place on the basis of the user&#8217;s ip address. Its light weight and free, rather than downloading bulky database and getting paid services, for getting <strong>latitude and longitude</strong> on the basis of IP.<br />
Here is the simplest way to do it. Requested to<strong> http://api.hostip.info/?ip=$ip&#038;position=true</strong> it responds XML formatted output. So we need to parse XML code using DOM class of PHP.<strong>(#19-#23)</strong>. Remember, the <strong>position=true</strong> should be set to get the latitude and longitude otherwise it will not show on default.<br />
<!--readmore--><br />
Here is the code and I will soon upload the working demo.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?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);

    if($ipcheck == -1 || $ipcheck === false){
		echo &quot;ERROR: INVALID IP&quot;;
		exit;
	}
	else
		$uri = &quot;http://api.hostip.info/?ip=$ip&amp;position=true&quot;;
 	$dom-&gt;load($uri);
	$name=$dom-&gt;getElementsByTagNameNS('http://www.opengis.net/gml','name')-&gt;item(1)-&gt;nodeValue;
	$coordinates=$dom-&gt;getElementsByTagNameNS('http://www.opengis.net/gml','coordinates')-&gt;item(0)-&gt;nodeValue;
	$temp=explode(&quot;,&quot;,$coordinates);
	$latlngValue['LNG']=$temp[0];
	$latlngValue['LAT']=$temp[1];
	$latlngValue['NAME']=$name;
	return $latlngValue;

}
//calling the functions and setting on array $latlng
$IP=getRealIpAddr(); //from roshanbh.com.np
$latlng=IPtoLatLng($IP);
?&gt;
</pre>
<p><strong>[UPDATE] <a href="http://subeshexamples.googlecode.com/files/ip.php">[DOWNLOAD]</a></strong><br />
Due to high request of the visitors I have posted the whole source code here.. just copy the PHP part above anywhere the script part and get the IP code from http://roshanbh.com.np/2007/12/getting-real-ip-address-in-php.html and run. Remember you need PHP5, because the DOM used is of PHP5.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
  &lt;head&gt;
    &lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=utf-8&quot;/&gt;
    &lt;title&gt;Google Maps Plotting  User By Refrence Of IP Address | Subesh.com.np&lt;/title&gt;

 &lt;script src=&quot;http://maps.google.com/maps?file=api&amp;amp;v=2&amp;amp;key=ABQIAAAAPHLcOOGHX2-uLk3K8q1nMRSFS3Iba-Yq79Uuy07kI14Q-o9MOhQTADZYj-oIAYvmRBVx8i9NqeBSjg&quot;
      type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot;&gt;
    //&lt;![CDATA[

    var iconBlue = new GIcon();
    iconBlue.image = 'http://labs.google.com/ridefinder/images/mm_20_blue.png';
    iconBlue.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconBlue.iconSize = new GSize(12, 20);
    iconBlue.shadowSize = new GSize(22, 20);
    iconBlue.iconAnchor = new GPoint(6, 20);
    iconBlue.infoWindowAnchor = new GPoint(5, 1);

	var point = new GLatLng(parseFloat('&lt;?=$latlng['LAT']?&gt;'),parseFloat('&lt;?=$latlng['LNG']?&gt;'));

		function load() {
		  if (GBrowserIsCompatible()) {
			var map = new GMap2(document.getElementById(&quot;map&quot;));
			map.setCenter(new GLatLng(parseFloat('&lt;?=$latlng['LAT']?&gt;'),parseFloat('&lt;?=$latlng['LNG']?&gt;')),3);
			var marker = createMarker(point);
            map.addOverlay(marker);
		}
	}

	 function createMarker(point) {
      var marker = new GMarker(point, iconBlue);
      var html = &quot;&lt;h1&gt;Gothcha! HA HA &lt;/h1&gt; &lt;br /&gt;You Are Here !&lt;br /&gt;&lt;b&gt;&lt;?=$latlng['NAME']?&gt;&lt;/b&gt; &quot;;
      GEvent.addListener(marker, 'mouseover', function() {
        marker.openInfoWindowHtml(html);
      });
      return marker;
    }
 //]]&gt;

  &lt;/script&gt;
 &lt;/head&gt;
  &lt;body onload=&quot;load()&quot; onunload=&quot;GUnload()&quot;&gt;
  &lt;h1&gt;Subesh.com.np: Maps Example&lt;/h1&gt;
   &lt;div id=&quot;map&quot; style=&quot;width: 500px; height: 300px&quot;&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2008/07/mapping-the-ip-address-to-latitude-and-longitude-in-google-maps/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
	</channel>
</rss>

