<?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>unitstep.net &#187; geolocation</title>
	<atom:link href="http://unitstep.net/blog/category/geolocation/feed/" rel="self" type="application/rss+xml" />
	<link>http://unitstep.net</link>
	<description>the home of peter chng</description>
	<lastBuildDate>Mon, 19 Mar 2012 01:49:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Toronto goes open&#8230; sort of</title>
		<link>http://unitstep.net/blog/2009/11/28/toronto-goes-open-sort-of/</link>
		<comments>http://unitstep.net/blog/2009/11/28/toronto-goes-open-sort-of/#comments</comments>
		<pubDate>Sat, 28 Nov 2009 18:06:00 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
				<category><![CDATA[geolocation]]></category>
		<category><![CDATA[government]]></category>
		<category><![CDATA[maps]]></category>
		<category><![CDATA[society]]></category>
		<category><![CDATA[toronto]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[information]]></category>
		<category><![CDATA[mashups]]></category>
		<category><![CDATA[open]]></category>
		<category><![CDATA[web services]]></category>

		<guid isPermaLink="false">http://unitstep.net/?p=1061</guid>
		<description><![CDATA[Back on November 2nd, the City of Toronto launched their toronto.ca/open service &#8211; a project aimed to be the &#8220;official data set catalogue&#8221; of the city. Part of the OpenTO initiative to make various data that the city has collected available to developers in formats that make them easy to manipulate, toronto.ca/open is the first [...]]]></description>
			<content:encoded><![CDATA[<p class="image align-right"><a href="http://www.toronto.ca/open/index.htm"><img src="http://unitstep.net/wordpress/wp-content/uploads/2009/11/opento.jpg" alt="opento" title="opento" width="250" height="51" class="alignnone size-full wp-image-1077" /></a></p>
<p>Back on November 2nd, the City of Toronto launched their <a href="http://toronto.ca/open/">toronto.ca/open</a> service &#8211; a project aimed to be the &#8220;official data set catalogue&#8221; of the city.  Part of the OpenTO initiative to make various data that the city has collected available to developers in formats that make them easy to manipulate, <a href="http://toronto.ca/open/">toronto.ca/open</a> is the first step to making the city and its services more &#8220;open and accessible&#8221;.</p>
<p>The hope is that if the city makes this information available in a readily-usable form, developers will take the time to create various services around them, helping citizens enjoy and take advantage of what Toronto has to offer.  For example, data on garbage collection, public transit or upcoming city events could be used to create a service that would alert users through various means of communication.  But at present, the amount and types of data available are fairly limited.</p>
<p>Announced back in April at the <a href="http://www.meshconference.com/">Mesh Conference</a> in Toronto by Mayor David Miller, the openness initiative had a lot to live up to in the half-year following up to its release earlier this month at the <a href="http://rocket9broadcasting.com/Webcasts/2009/11/CoT/index.php?Page=Home">Toronto Innovation Showcase</a>.  </p>
<p>Several cities have already implemented similar projects, leaving Toronto to play catch-up.  Vancouver, for example, launched <a href="http://data.vancouver.ca/">their own Open Data initiative</a> earlier this year, and Toronto&#8217;s data catalogue appears to be modeled after it.  Edmonton, a much smaller and less dense city than Toronto, has also <a href="http://www.edmontonjournal.com/technology/Edmonton+moves+toward+open+data/2251768/story.html">recently begun an initiative</a> to open their city&#8217;s data to the public in a similar manner, <a href="http://wiki.changecamp.ca/ChangeCamp_Edmonton/The_Grid/Open_Data_in_Edmonton">with promising results</a>.</p>
<p>But the data is better late than never, so I applaud the City&#8217;s effort to democratize and help keep citizens better informed.</p>
<h2>The data itself</h2>
<p>Looking at <a href="http://www.toronto.ca/open/catalogue.htm">what&#8217;s offered</a>, you can see that most of the data sets or services have a geographical component to them.  This only makes sense, as hyperlocal information is always of great interest to most people.  </p>
<p>The data is presented in a variety of formats, but the most popular seems to be an <em>ESRI Shapefile</em>, a file format used by a <a href="http://en.wikipedia.org/wiki/Esri">popular suite of GIS software</a>.  With much of the data having a geospatial aspect to them, this makes sense as the data likely didn&#8217;t require much conversion before being released by the City. (I.E., they probably use ESRI&#8217;s application for city planning, etc.)</p>
<p>Thankfully, the format has been <a href="http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf">well-documented by its developer</a>, and <a href="http://en.wikipedia.org/wiki/Shapefile">Wikipedia as well</a>.  All of these ESRI Shapefiles are intended to be downloaded for offline use, as they are typically made available inside of a zip file.  Thus, the process of keeping them up to date may prove tedious, though I&#8217;m sure an enterprising developer could automate it nicely.</p>
<p>Other data has been made available in various <a href="http://www.w3.org/XML/" class="ubernym uttInitialism"><acronym class="uttInitialism" title="eXtensible Markup Language">XML</acronym></a> formats.  Some are intended to be accessed as online services, with a link to the <a href="http://www.w3.org/XML/" class="ubernym uttInitialism"><acronym class="uttInitialism" title="eXtensible Markup Language">XML</acronym></a> document and the corresponding XSD file, while at least one is presumably meant to be <a href="http://www.toronto.ca/open/datasets/apartment-standards/">used offline since it&#8217;s zipped up</a>.  Some of the <a href="http://www.w3.org/XML/" class="ubernym uttInitialism"><acronym class="uttInitialism" title="eXtensible Markup Language">XML</acronym></a> &#8220;Feeds&#8221; are also in a format without a defined schema and are not <acronym class="uttInitialism" title="Really Simple Syndication">RSS</acronym> or Atom feeds.  For example, the <a href="http://www.toronto.ca/open/datasets/festival-events/">feed of City-sponsored events</a> would be better served by an <acronym class="uttInitialism" title="Really Simple Syndication">RSS</acronym> or Atom feed, which would not only allow developers to integrate it into an application, but also regular users to sign up to the feed using any newsreader.</p>
<p>There are also some web services explicitly offered.  The first is a <a href="http://www.toronto.ca/open/datasets/geocoder-web-service/">geocoder service</a> that can be used to validate addresses and other place names within the City.  It is a WSDL service, and there is a full <acronym class="uttInitialism" title="Portable Document Format">PDF</acronym> file to document the input parameters and expected output.</p>
<p>The second is a series of services that provide access to &#8220;<a href="http://www.toronto.ca/open/datasets/web-map-services/">live geospatial data from the City of Toronto</a>&#8220;.  These are all <a href="http://en.wikipedia.org/wiki/Web_Map_Service">Web Map Services</a> that conform to a protocol specification developed by the <a href="http://www.opengeospatial.org/">Open Geospatial Consortium</a>.  It would have been nice if they had linked to the <a href="http://portal.opengeospatial.org/files/?artifact_id=4756">WMS Specification</a> (<acronym class="uttInitialism" title="Portable Document Format">PDF</acronym> document) that explained how to query the services, instead of forcing you to find out the information yourself. (See page 14 and onwards of the mentioned document)</p>
<p>Lastly, some of the data is offered in plain old text files. In particular, the <a href="http://www.toronto.ca/open/datasets/ttc-routes/">TTC Routes and Schedules</a> is only available as a series of zipped text files that are periodically updated, presumably manually.  This may be a bit backwards, but thankfully the formatting is <a href="http://www.toronto.ca/open/datasets/ttc-routes/metadata-routes-schedules-1.pdf">well-defined</a>.</p>
<h2>Drawbacks</h2>
<p>Though it may not be fair to criticize at this point, there are some clear limitations to the data.  Firstly, much of the data is intended to be downloaded and then used in an &#8220;offline&#8221; capacity, that is, without further communication between the application and the City&#8217;s servers that host the data.  Though this was probably done due to technical limitations (i.e. reducing bandwidth usage), it limits the ability of an application to stay up to date with the latest data.  For things like the TTC Route and Schedules and the list of <a href="http://www.toronto.ca/open/datasets/apartment-standards/">Apartment Bylaw Infractions</a>, this severely reduced their effectiveness as the data will likely need to be periodically manually updated.</p>
<p>Furthermore, the current data set is somewhat limited and may impede the usefulness of any applications or services that can be developed.  For example, making real-time TTC updates and other data available would be an immense benefit, yet the only TTC data currently available are in zipped text files that are only periodically updated.  Thankfully, the City has <a href="http://www.datato.org/app/">setup a site to allow users to request more data</a>, and there are already <a href="http://www.datato.org/app/need/show/20">many requests</a> for <a href="http://www.datato.org/app/need/show/46">more TTC data</a>. </p>
<p>It would also be nice if crime statistics for Toronto could be made available in an easy to use format.  In particular, the underlying data used by the TPS to produce <a href="http://www.torontopolice.on.ca/statistics/">their crime maps and statistics</a> could be beneficial in developing all sorts of interesting maps.  In fact, this is what the <a href="http://thestar.blogs.com/maps/neighbourhood-crime-maps/">Toronto Star has been doing for some time</a>, but they had to get the data through an explicit request under access-to-information legislation.  Since then, they&#8217;ve produced some <a href="http://www3.thestar.com/static/Flash/inmates/index.html">very interesting maps</a> and it would be beneficial if everyone had access to the same data so that the maps could be improved upon and kept up to date.</p>
<p>Producing such crime-based maps can provide people with one more factor to help them determine what part of the City they&#8217;d like to live in, or just allow them to have access to accurate statistics on crime.  Not all of this is negative &#8211; as any study of crime in Toronto will show that it&#8217;s been following a downward trend for quite some time, so such information could help ward off any potential negative spin that media may put on crime.  However, I do realize the privacy implications that come with releasing such data, so time should be taken to ensure that it is released in a manner where anonymity is preserved as best as possible.</p>
<p>Lastly, it&#8217;s important to note that the OpenTO initiative is still at a very early stage.  Even with the way things move at City Hall, things will eventually improve.  It&#8217;s also very important to give your feedback, either at <a href="http://www.datato.org/app/">DataTO</a> or directly by email to <a href="mailto:opendata@toronto.ca">opendata@toronto.ca</a>.  Additionally, if you&#8217;re a developer, the <a href="http://groups.google.com/group/datato?pli=1">corresponding Google Group</a> is a good place to get started.  Even with the current limitations, I am sure we&#8217;ll see some great applications developed based on the data.  One need <a href="http://myttc.ca/">only to look at MyTTC</a> to see what can be done with some effort and ingenuity &#8211; and this was done well <em>before</em> the City officially released any data!</p>
<hr/>Copyright &copy; 2012 <strong><a href="http://unitstep.net">unitstep.net</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact <strong><a href="mailto:webmaster@unitstep.net">webmaster@unitstep.net</a></strong> for more information.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span>]]></content:encoded>
			<wfw:commentRss>http://unitstep.net/blog/2009/11/28/toronto-goes-open-sort-of/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Street View finally comes to Canada</title>
		<link>http://unitstep.net/blog/2009/10/17/google-street-view-finally-comes-to-canada/</link>
		<comments>http://unitstep.net/blog/2009/10/17/google-street-view-finally-comes-to-canada/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 17:45:43 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
				<category><![CDATA[canada]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[government]]></category>
		<category><![CDATA[maps]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[privacy]]></category>
		<category><![CDATA[street-view]]></category>

		<guid isPermaLink="false">http://unitstep.net/?p=1031</guid>
		<description><![CDATA[After much delay, possibly due to government meddling, Google Street View finally went live in select Canadian cities last week! Most of the GTA is covered, along with Kitchener/Waterloo, Ottawa, Montreal, Quebec City, Halifax, Calgary and Vancouver. This likely ensures coverage for a majority of Canada&#8217;s population, if only a very small minority of its [...]]]></description>
			<content:encoded><![CDATA[<p class="image align-right"><a href="http://unitstep.net/wordpress/wp-content/uploads/2009/10/google-street-view-canada.jpg"><img src="http://unitstep.net/wordpress/wp-content/uploads/2009/10/google-street-view-canada-150x150.jpg" alt="google-street-view-canada" title="google-street-view-canada" width="150" height="150" class="alignnone size-thumbnail wp-image-1049" /></a></p>
<p>After much delay, possibly due to government meddling, Google Street View <a href="http://www.cbc.ca/technology/story/2009/10/07/tech-internet-google-street-view-toronto.html">finally went live in select Canadian cities</a> last week! Most of the GTA is covered, along with Kitchener/Waterloo, Ottawa, Montreal, Quebec City, Halifax, Calgary and Vancouver.  This likely ensures coverage for a majority of Canada&#8217;s population, if only a very small minority of its geographical area.</p>
<p>This is a welcome move, since street view has been available for our neighbours to the south for the past two years.</p>
<p>According to some reports, Street View was <a href="http://network.nationalpost.com/np/blogs/toronto/archive/2009/04/09/toronto-s-google-street-view-goes-live-within-weeks.aspx">supposed to launch in Canada earlier this year</a>, and some of the imagery was collected as early as 2007. (Though the images around my area seem to be from early this year) Oh well, this is better late than never!</p>
<p>I&#8217;m speculating that the government&#8217;s concern with Google Street View may have slowed deployment, as in 2007 the privacy commissioner <a href="http://www.cbc.ca/canada/story/2007/09/11/streetview-commissioner-privacy.html">voiced strong concerns against the technology</a>.  I&#8217;ve never believed any of that FUD, but it seems that their concerns have been addressed with Google&#8217;s automatic detection and blurring of faces and license plates, along with new straightforwards processes to request that your image be removed from the service.</p>
<p>But it&#8217;s still been much ado about nothing, not really like the <a href="http://mashable.com/2009/07/17/canada-facebook-privacy/">conflict between the government and Facebook</a> earlier this year, which was also <a href="http://www.thestar.com/news/canada/article/682182">subsequently resolved</a>.  In the case with Facebook, privacy settings were often complicated and unclear; with Google Street view, they&#8217;re merely providing public views of public places, so I don&#8217;t see what the problem with that is.</p>
<h2>Also available on the iPhone/iPod Touch</h2>
<p>You can also use Street View on the built in Maps app for the iPhone OS, though it&#8217;s a <a href="http://googlesightseeing.com/2008/11/24/google-street-view-on-iphone/">bit convoluted</a> since there&#8217;s no &#8220;Street View&#8221; button to toggle.  Instead, you must first drop a pin (click on the &#8220;layer peel back&#8221; icon in the lower right corner) and then bring up the dialog box for that pin.  If it&#8217;s in an area with Street View present, the little guy icon on the left will be lit up and you should be able to click it to <a href="http://mashable.com/2009/10/07/google-street-view-canada/">bring up Street View</a>.</p>
<p>Street View only works in landscape mode but it&#8217;s still pretty useful for getting to know an area before you visit it for the first time.  Sometimes an actual image can convey sense better than just a map.</p>
<h2>Competition?</h2>
<p>It remains to be seen how the launch of Street View in Canada will fare for the similar service launched by Canpages in BC.  That service only covers <a href="http://communities.canada.com/vancouversun/blogs/techsense/archive/2009/10/07/google-street-view-launches-in-canada-today.aspx">Vancouver, Whistler and Squamish</a> but was launched back in March.</p>
<p>Nonetheless, it&#8217;s very neat technology, even if it was originally unveiled over two years ago.  Witness this by the fact that reporters are still drooling over it by embedding the service in <a href="http://www.theglobeandmail.com/news/technology/google-street-view-comes-to-canada/article1315242/">every article covering the launch</a>.</p>
<hr/>Copyright &copy; 2012 <strong><a href="http://unitstep.net">unitstep.net</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact <strong><a href="mailto:webmaster@unitstep.net">webmaster@unitstep.net</a></strong> for more information.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span>]]></content:encoded>
			<wfw:commentRss>http://unitstep.net/blog/2009/10/17/google-street-view-finally-comes-to-canada/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Determine your visitor&#8217;s location based on IP address</title>
		<link>http://unitstep.net/blog/2009/06/29/determine-your-visitors-location-based-on-ip-address/</link>
		<comments>http://unitstep.net/blog/2009/06/29/determine-your-visitors-location-based-on-ip-address/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 02:37:17 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[maps]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[ip address]]></category>
		<category><![CDATA[location]]></category>
		<category><![CDATA[lookup ip-geolocation]]></category>

		<guid isPermaLink="false">http://unitstep.net/?p=935</guid>
		<description><![CDATA[If you&#8217;re running a website that provides a service, it&#8217;s likely that it would be beneficial to know a user&#8217;s location (or have a rough idea) so that the content could be tailored to their specific geographic area. But how do you get their location, without having to ask them? By using their IP address, [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re running a website that provides a service, it&#8217;s likely that it would be beneficial to know a user&#8217;s location (or have a rough idea) so that the content could be tailored to their specific geographic area.  But how do you get their location, without having to ask them? By using their IP address, it&#8217;s possibly to determine their general area with fairly good accuracy. In this tutorial, I&#8217;ll explain how to do that using the free <a href="http://ipinfodb.com/ip_database.php">IP address geolocation database</a> from <a href="http://ipinfodb.com/">IPInfoDB</a>.</p>
<h2>Motivation and Usage</h2>
<p>There are numerous reasons for using the user&#8217;s location to improve the quality of a service.  For example, the restaurant guide and review site, <a href="http://www.restaurantica.com/">Restaurantica</a>, automatically makes a guess as to your location and populates the &#8220;Search&#8221; field so that you are one click away from finding information tailored to your geographic area.  </p>
<p>This determination is based on the user&#8217;s IP address.  Usually, the lookup is done based on a static set of mappings from IP addresses to geographical locations, like cities.  In fact, this is exactly what the <a href="http://ipinfodb.com/ip_database.php">IP address geolocation database</a> (that we&#8217;ll use) does.  It has the advantage of being easy to understand but unfortunately the accuracy can degrade over time, as IP addresses are usually not hardwired to specific locations.  For example, most DSL users are subject to DHCP, so the same IP address may be re-used across different cities. (The IP address database from IPInfoDB is updated periodically to help reduce this inaccuracy)</p>
<p>Thus, you should not rely on the information provided to be 100% accurate; it should only be used as a suggestion.  This is why <a href="http://www.restaurantica.com/">Restaurantica</a> only <em>populates</em> the search field with your estimated location, rather than giving you the results for that location right away; if it was wrong, the results for a different location would certainly be confusing to a user.  This gives the user a chance to correct any inaccurate lookups.</p>
<h2>Using the IP Address geolocation database</h2>
<p>The first step is to <a href="http://ipinfodb.com/ip_database.php">download the database</a> and import it into your local database; for this example I&#8217;ll use MySQL.  Note that the site also offers an <a href="http://ipinfodb.com/ip_location_api.php">IP location Lookup API</a>, which has the advantage of not requiring a local database but may be subject to usage limits; if you&#8217;ll be getting a lot of traffic you&#8217;ll be better off using the local database.</p>
<h3>Import the contents into MySQL</h3>
<p>I downloaded the <a href="http://mirrors.portafixe.com/ipinfodb/ip_database/current/ipinfodb_one_table_full.sql.bz2">Complete (City) database as one table in SQL format</a>.  Extracting the file from the archive, you&#8217;ll see that it&#8217;s well over 300 MB in size. If you&#8217;re fond of using <a href="http://www.phpmyadmin.net/home_page/index.php">phpMyAdmin</a>, you unfortunately won&#8217;t be able to import such a large file using that tool, so we&#8217;ll have to rely on the command line to import the contents.  Go to your <code>mysql/bin</code> folder and enter the following command, assuming you extracted the SQL file to the same location:</p>
<pre><code>mysql -u root -p [name of database] &lt; ipinfodb_one_table_full.sql</code></pre>
<p><strong>Running this command will take some time, as it won&#8217;t be fast having to import such a huge table</strong>.  Take a break and come back in a few minutes. <img src='http://unitstep.net/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  (You may want to create a new database to hold just this table, do that before running this command)  After that&#8217;s done, you should be able to see the contents in phpMyAdmin, like below:</p>
<p class="image">
<a href="http://unitstep.net/wordpress/wp-content/uploads/2009/06/ip-geolocation-1.jpg"><img src="http://unitstep.net/wordpress/wp-content/uploads/2009/06/ip-geolocation-1-300x84.jpg" alt="ip-geolocation-1" title="ip-geolocation-1" width="300" height="84" class="alignnone size-medium wp-image-945" /></a>
</p>
<h3>Using the database</h3>
<p>Querying the database is straightforward, and the IP Info DB website has plenty of examples <a href="http://ipinfodb.com/ip_database.php">at the bottom of the download page</a>.  Basically, once you have the user&#8217;s IP, you can use a query like this to find the most likely city it originated from:</p>
<pre><code>SELECT *
FROM `ip_group_city`
WHERE `ip_start` &lt;= INET_ATON([ip address as a string])
ORDER BY ip_start DESC
LIMIT 1;</code></pre>
<p>The INET_ATON function converts a string that is the dotted-quad octet form of an IP address (the form you&#8217;re most used to seeing) into a 32-bit unsigned integer.  This integer is then used to locate the record that most likely corresponds to the geographical location.  The database is structured such that row with the highest <code>ip_start</code> value not greater than the given IP address is deemed to be the most likely location.</p>
<p>An example:</p>
<pre><code>SELECT * FROM `ip_group_city` WHERE `ip_start` &lt;= INET_ATON('69.156.150.155') ORDER BY ip_start DESC limit 1;</code></pre>
<p>(This returns the city of Toronto, Ontario, Canada) If you want to get a list of likely locations, just increase the LIMIT argument to something like 10, and this will return 10 locations that are likely close to where the IP address is located.  <strong>Note that there may be duplicates in this list</strong>.</p>
<h2>A simple example</h2>
<p>Here&#8217;s a simple <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym> script that takes the user&#8217;s IP address and displays their most likely location on a map using the <a href="http://code.google.com/apis/maps/documentation/staticmaps/">Google Static Maps API</a>.</p>
<pre><code>&lt;?php
$ipGeolocationDatabaseName = 'ip_geolocation';

$link = mysql_connect('localhost', 'root', '');
$ipAddress = mysql_real_escape_string($_SERVER['REMOTE_ADDR']);

echo $ipAddress;

mysql_select_db($ipGeolocationDatabaseName, $link);

$query = "SELECT * FROM `ip_group_city` " .
         "WHERE `ip_start` &lt;= INET_ATON( '$ipAddress' ) " .
         "ORDER BY ip_start DESC " .
         "LIMIT 1";
$resultLocation = mysql_query($query);

$numRows = mysql_num_rows($resultLocation);

if (0 == $numRows)
{
  echo "No likely locations found.";
}

while ($row = mysql_fetch_array($resultLocation))
{
  echo "&lt;pre&gt;";
  print_r($row);
  echo "&lt;/pre&gt;";

  $lat = urlencode($row['latitude']);
  $lng = urlencode($row['longitude']);
  if (!empty($lat) &amp;&amp; !empty($lng))
  {
    // NOTE: Replace the `key` parameter with your own, obtained from:
    // http://code.google.com/apis/maps/signup.html
    // (The one in use is only good for URLs on `localhost`)
    $queryString = "center=$lat,$lng";
    $queryString .= "&amp;zoom=10";
    $queryString .= "&amp;size=300x300";
    $queryString .= "&amp;markers=$lat,$lng,blue";
    $queryString .= "&amp;key=ABQIAAAAicCf6MqoHlR-MsfivtVWPRT2yXp_ZAY8_ufC3CFXhHIE1NvwkxTNmqRdvnM9orG9QdyALHoUZfmFuQ";
    $queryString .= "&amp;sensor=false";

    echo '&lt;img src="http://maps.google.com/staticmap?' . htmlentities($queryString) . '" alt="location" /&gt;';
  }
}
?&gt;</code></pre>
<p>Here&#8217;s what it display for my IP address:</p>
<p class="image">
<a href="http://unitstep.net/wordpress/wp-content/uploads/2009/06/ip-geolocation-2.jpg"><img src="http://unitstep.net/wordpress/wp-content/uploads/2009/06/ip-geolocation-2.jpg" alt="ip-geolocation-2" title="ip-geolocation-2" width="300" height="300" class="alignnone size-full wp-image-956" /></a>
</p>
<p>As you can see, it&#8217;s not always accurate, but it&#8217;s a good start to enhancing your website to offer localized services and features.</p>
<hr/>Copyright &copy; 2012 <strong><a href="http://unitstep.net">unitstep.net</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact <strong><a href="mailto:webmaster@unitstep.net">webmaster@unitstep.net</a></strong> for more information.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span>]]></content:encoded>
			<wfw:commentRss>http://unitstep.net/blog/2009/06/29/determine-your-visitors-location-based-on-ip-address/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

