<?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>Smiths R Us &#187; GPS</title>
	<atom:link href="http://smithsrus.com/tag/gps/feed/" rel="self" type="application/rss+xml" />
	<link>http://smithsrus.com</link>
	<description>Technology, home automation, usability, and whatever else amuses me.</description>
	<lastBuildDate>Mon, 19 Jul 2010 17:38:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>GPS Geolocation in Safari on iPhone OS 3.0</title>
		<link>http://smithsrus.com/gps-geolocation-in-safari-on-iphone-os-3-0/</link>
		<comments>http://smithsrus.com/gps-geolocation-in-safari-on-iphone-os-3-0/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 02:00:59 +0000</pubDate>
		<dc:creator>Doug Smith</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[GPS]]></category>

		<guid isPermaLink="false">http://smithsrus.com/?p=157</guid>
		<description><![CDATA[I just updated my iPhone to the shiny new OS 3.0. Apple did a great job addressing a few shortcomings and adding new features. Others have already told about the common features so I won&#8217;t rehash them here. But let me tell you about my favorite new feature: Safari can now get your GPS location [...]]]></description>
			<content:encoded><![CDATA[<p>I just updated my iPhone to the shiny new OS 3.0. Apple did a great job addressing a few shortcomings and adding new features. Others have already <a href="http://www.ismashphone.com/2009/06/how_to_use_best_40_features_of_iphone_3.html">told about the common features</a> so I won&#8217;t rehash them here.</p>
<p>But let me tell you about my favorite new feature: Safari can now get your GPS location via javascript!<span id="more-157"></span> This is usually referred to as <em>geolocation</em>. You can easily grab the current location or get periodic updates.</p>
<p>Okay, so I&#8217;m excited over what may seem like an obscure geeky feature, but I think it&#8217;s a big deal. </p>
<h3>Why GPS in Safari is a Big Deal</h3>
<ol>
<li>
<p><strong>Location aware Web pages:</strong> Have you ever gone to a company&#8217;s Web site to find their nearest location? You usually have to type in your zip code. But what if you&#8217;re traveling and don&#8217;t know your zip code? Safari knowing your location solves that problem.
</li>
<li>
<p><strong>Location aware Web applications:</strong> It&#8217;s fairly easy to create Web content looks and behaves like an iPhone application. Now those can take advantage of location information.
<p>For example, I&#8217;ve been working with a company on an iPhone Web application that interacts with their internal customer database. Field reps can now easily find customers within a certain radius of the rep&#8217;s current location who meet various other criteria.</p>
</li>
</ol>
<h3>Web Geolocation Privacy and Standards</h3>
<p>Don&#8217;t worry, all of this is built with good privacy controls. You are asked permission before your location data is revealed to a site. For convenience, it stops asking about a particular site after you have approved it a few times.</p>
<p>These location features are based on the upcoming <a href="http://dev.w3.org/geo/api/spec-source.html">Geolocation API Specification</a>. Because it&#8217;s not just a proprietary Safari thing it should get widespread adoption. In fact, it&#8217;s already built into the latest Firefox 3.5 beta.</p>
<h3>Web Geolocation Sample Code</h3>
<p>The specifications do a good job of explaining the parts so no need to go over all of that. However, it&#8217;s worth pointing out how to check and see if geolocation features are available or not and take appropriate action. For example, you may only want to show GPS options if it can actually be used. This simple snippet will do the job.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><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>  
	<span style="color: #009966; font-style: italic;">/* Code if geolocation is available. */</span>  
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>  
	<span style="color: #009966; font-style: italic;">/* Code if geolocation is not available */</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Let&#8217;s put it all together in a simple Web page that displays all of the geolocation variables for your current location. The code is below or you can try my <a href="http://smithsrus.com/geo.html">geolocation test page</a> from your iPhone.</p>
<p>(Yes, you&#8217;ll probably want to use modern DOM techniques for a real project. The purpose of this is just to show a simple working example.)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;!</span>DOCTYPE html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html lang<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;en&quot;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>meta http<span style="color: #339933;">-</span>equiv<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;content-type&quot;</span> content<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/html; charset=utf-8&quot;</span><span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>meta <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;viewport&quot;</span> content<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;&quot;</span> <span style="color: #339933;">/&gt;</span>
		<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>Geolocation Test<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
&nbsp;
		<span style="color: #339933;">&lt;</span>script language<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;javascript&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
			<span style="color: #003366; font-weight: bold;">function</span> getLocation<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #006600; font-style: italic;">// Get location no more than 10 minutes old. 600000 ms = 10 minutes.</span>
				navigator.<span style="color: #660066;">geolocation</span>.<span style="color: #660066;">getCurrentPosition</span><span style="color: #009900;">&#40;</span>showLocation<span style="color: #339933;">,</span> showError<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>enableHighAccuracy<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>maximumAge<span style="color: #339933;">:</span><span style="color: #CC0000;">600000</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #003366; font-weight: bold;">function</span> showError<span style="color: #009900;">&#40;</span>error<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>error.<span style="color: #660066;">code</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">' '</span> <span style="color: #339933;">+</span> error.<span style="color: #660066;">message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #003366; font-weight: bold;">function</span> showLocation<span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				geoinfo.<span style="color: #660066;">innerHTML</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'&lt;p&gt;Latitude: '</span> <span style="color: #339933;">+</span> position.<span style="color: #660066;">coords</span>.<span style="color: #660066;">latitude</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/p&gt;'</span> 
				<span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;p&gt;Longitude: '</span> <span style="color: #339933;">+</span> position.<span style="color: #660066;">coords</span>.<span style="color: #660066;">longitude</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/p&gt;'</span> 
				<span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;p&gt;Accuracy: '</span> <span style="color: #339933;">+</span> position.<span style="color: #660066;">coords</span>.<span style="color: #660066;">accuracy</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/p&gt;'</span> 
				<span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;p&gt;Altitude: '</span> <span style="color: #339933;">+</span> position.<span style="color: #660066;">coords</span>.<span style="color: #660066;">altitude</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/p&gt;'</span> 
				<span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;p&gt;Altitude accuracy: '</span> <span style="color: #339933;">+</span> position.<span style="color: #660066;">coords</span>.<span style="color: #660066;">altitudeAccuracy</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/p&gt;'</span> 
				<span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;p&gt;Speed: '</span> <span style="color: #339933;">+</span> position.<span style="color: #660066;">coords</span>.<span style="color: #660066;">speed</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/p&gt;'</span> 
				<span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;p&gt;Heading: '</span> <span style="color: #339933;">+</span> position.<span style="color: #660066;">coords</span>.<span style="color: #660066;">heading</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/p&gt;'</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>script language<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;javascript&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>	
			<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>  
				document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;p&gt;&lt;input type=&quot;button&quot; onclick=&quot;getLocation()&quot; value=&quot;Show Geolocation Information&quot; /&gt;&lt;/p&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>  
				document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;p&gt;Sorry, your device or browser software does not appear to support geolocation services.&lt;/p&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
			<span style="color: #009900;">&#125;</span>  
		<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
&nbsp;
		<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;geoinfo&quot;</span><span style="color: #339933;">&gt;&lt;/</span>div<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></div></div>

<p>I can&#8217;t wait to see some of the great things others will create by combining Web sites with location. And it will only get better as more devices become location aware. Be sure to let me know of good location-aware sites and web apps you run across.</p>
<p>Now go create something cool!</p>
]]></content:encoded>
			<wfw:commentRss>http://smithsrus.com/gps-geolocation-in-safari-on-iphone-os-3-0/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced)

Served from: smithsrus.com @ 2010-07-31 03:34:14 -->