<?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>Che Hodgins &#187; javascript</title>
	<atom:link href="http://www.chehodgins.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chehodgins.com</link>
	<description>Musings on Web Development</description>
	<lastBuildDate>Tue, 24 Nov 2009 02:39:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Advanced Geolocation</title>
		<link>http://www.chehodgins.com/web/advanced-geolocation/</link>
		<comments>http://www.chehodgins.com/web/advanced-geolocation/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 04:43:05 +0000</pubDate>
		<dc:creator>chehodgins</dc:creator>
				<category><![CDATA[geolocation]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://www.chehodgins.com/?p=295</guid>
		<description><![CDATA[I write this in honor of the Firefox web browser. I still remember when it was first released November 9th, 2004, and gave me hope for a better, nicer, non-IE world. Today, Firefox 3.5 is released. Building upon nearly 5 years of success, they have continued innovating and I thank them for making the web [...]]]></description>
			<content:encoded><![CDATA[<p>I write this in honor of the Firefox web browser. I still remember when it was first released November 9th, 2004, and gave me hope for a better, nicer, non-IE world. Today, Firefox 3.5 is released. Building upon nearly 5 years of success, they have continued innovating and I thank them for making the web a better place.</p>
<p>Feel free to <a href="http://www.chehodgins.com/geo.html">Skip to the demo</a>.</p>
<p>I <a href="http://www.chehodgins.com/php/free-and-fast-geolocation-in-php/">previously wrote</a> about using IP based Geolocation. Although this method is widely used, the downsides are obvious: inaccurate results, proxies, false positives, and a lack of privacy control for the end user. </p>
<p><strong>The Future of Geolocation</strong></p>
<p>The new generation of browsers are implementing the <a href="http://dev.w3.org/geo/api/spec-source.html">Geolocation API specification</a>. This gives the browser the job of figuring out where you are. There are some positive points and negative points to this. Firstly, the position of the user can be more accurate. In IP-based Geolocation, the only data available is the IP address. The browser has access to much more precise data such as WiFi networks and GPS devices (iPhone!). Secondly, privacy settings. The browser should be able to ask the user if they will allow such information to be shared, ideally even the level of accuracy that should be shown. This is possible if implemented in the browser. One negative point is something we are all familiar with: cross-browser compatibility. Different implementations in different web browser will make developers miserable, but hey, that&#8217;s what standards are for, right? <img src='http://www.chehodgins.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Browser Support</strong></p>
<p>As of today a few web browsers support geolocation. Here&#8217;s the status of the mainstream browsers:</p>
<ul>
<li>Firefox: Available in version 3.5, released today.</li>
<li>iPhone Safari: Available in OS3.</li>
<li>IE: Experimental in version 8.</li>
<li>Opera: Available in <a href="http://labs.opera.com/news/2009/03/26/">nightly builds</a> since March 2009.</li>
<li>Chrome: Available through <a href="http://veerasundar.com/blog/2009/06/coming-up-in-html5-geolocation-api-support-in-browsers/">Google Gears API</a></li>
<li>Safari: Unknown.</li>
</ul>
<p>Here is how to request a users location (see line 26 for the goods):</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">function</span> knownLocation<span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> latitude<span style="color: #339933;">,</span> longitude<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>position.<span style="color: #660066;">coords</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// iPhone</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; latitude <span style="color: #339933;">=</span> position.<span style="color: #660066;">coords</span>.<span style="color: #660066;">latitude</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; longitude <span style="color: #339933;">=</span> position.<span style="color: #660066;">coords</span>.<span style="color: #660066;">longitude</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// Firefox</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; latitude <span style="color: #339933;">=</span> position.<span style="color: #660066;">latitude</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; longitude <span style="color: #339933;">=</span> position.<span style="color: #660066;">longitude</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> div <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'geo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; div.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> div.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;Latitude: &quot;</span> <span style="color: #339933;">+</span> latitude <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;br/&gt;Longitude: &quot;</span> <span style="color: #339933;">+</span> longitude<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #003366; font-weight: bold;">function</span> unknownLocation<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> div <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'geo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; div.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> div.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;Unknown Location&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
window.<span style="color: #000066;">onload</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> div <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'geo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; div.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> div.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;Browser: &quot;</span> <span style="color: #339933;">+</span> navigator.<span style="color: #660066;">appName</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; (&quot;</span> <span style="color: #339933;">+</span> navigator.<span style="color: #660066;">appVersion</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;)&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>navigator.<span style="color: #660066;">geolocation</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; navigator.<span style="color: #660066;">geolocation</span>.<span style="color: #660066;">getCurrentPosition</span><span style="color: #009900;">&#40;</span>knownLocation<span style="color: #339933;">,</span> unknownLocation<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; div.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> div.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;Browser not supported&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>This then prompts the user for their approval:</p>
<p><a href="http://www.chehodgins.com/wp-content/uploads/2009/06/firefox3.5_geolocation.png"><img src="http://www.chehodgins.com/wp-content/uploads/2009/06/Picture-1-1024x139.png" alt="Geolocation in Firefox 3.5" title="Geolocation in Firefox 3.5" width="1024" height="139" class="aligncenter size-large wp-image-313" /></a></p>
<p>Similarly, on the iPhone:</p>
<p><img alt="" src="http://farm4.static.flickr.com/3620/3673686739_65c1cae92f.jpg?v=0" title="Geolocation on iPhone Safari" class="alignnone" width="320" height="480" /></p>
<p><strong>Conclusion</strong></p>
<p>This is really cool. With geolocation implemented in the browser, great precision can be achieved. For example, on the iPhone the GPS is used, so visiting the <a href="http://www.chehodgins.com/geo.html">demo page</a> from my living room gives different coordinates than when visiting from my kitchen. I can imagine many useful applications of this. Another thing I love is that I can deny my location to certain sites, which I will absolutely use on certain sites.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chehodgins.com/web/advanced-geolocation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
