<?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>bemoko&#039;s blog on mobile &#187; safari</title>
	<atom:link href="http://blog.bemoko.com/tag/safari/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.bemoko.com</link>
	<description>mobile made simple</description>
	<lastBuildDate>Wed, 25 Jan 2012 13:32:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>iPhone 3.0 geolocation javascript API</title>
		<link>http://blog.bemoko.com/2009/06/17/iphone-30-geolocation-javascript-api/</link>
		<comments>http://blog.bemoko.com/2009/06/17/iphone-30-geolocation-javascript-api/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 21:04:42 +0000</pubDate>
		<dc:creator>Ian Walsh</dc:creator>
				<category><![CDATA[mobile web]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[iphone 3.0]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[LBS]]></category>
		<category><![CDATA[safari]]></category>

		<guid isPermaLink="false">http://blog.bemoko.com/?p=415</guid>
		<description><![CDATA[With the iPhone 3.0 firmware released today, I thought I&#8217;d show you how to access one of the features I&#8217;ve been most looking forward to &#8211; support for the geolocation API in Safari means I can now create location aware websites. This will be just a quick demo to retrieve and display the current longitue [...]]]></description>
			<content:encoded><![CDATA[<p>With the iPhone 3.0 firmware released <a title="today" href="http://www.apple.com/uk/iphone/softwareupdate/">today</a>, I thought I&#8217;d show you how to access one of the features I&#8217;ve been most looking forward to &#8211; support for the <a title="geolocation" href="http://dev.w3.org/geo/api/spec-source.html">geolocation API</a> in Safari means I can now create location aware websites.</p>
<p>This will be just a quick demo to retrieve and display the current longitue and latitude of your phone, along with a googlemap so we can see if the results are right.  The more interesting applications will come&#8230;.</p>
<p>To do this we&#8217;ll use javascript and the newly added <a title="Navigator.Geolocation" href="http://dev.w3.org/geo/api/spec-source.html#geolocation">Navigator.Geolocation</a> interface to call the <a title="getCurrentPosition" href="http://dev.w3.org/geo/api/spec-source.html#get-current-position">getCurrentPosition</a>() function to retrieve the current longitude and latitude of the phone, which we&#8217;ll display and pass to the googlemaps API.</p>
<p>The code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;?</span>xml version<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;1.0&quot;</span> encoding<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;UTF-8&quot;</span><span style="color: #339933;">?&gt;</span>
<span style="color: #339933;">&lt;!</span>DOCTYPE html <span style="color: #003366; font-weight: bold;">PUBLIC</span> <span style="color: #3366CC;">&quot;-//WAPFORUM//DTD XHTML Mobile 1.0//EN&quot;</span> <span style="color: #3366CC;">&quot;http://www.wapforum.org/DTD/xhtml-mobile10.dtd&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html xmlns<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://www.w3.org/1999/xhtml&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>title<span style="color: #339933;">&gt;</span>iPhone <span style="color: #CC0000;">3.0</span> geolocation demo<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>meta 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: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;viewport&quot;</span><span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #003366; font-weight: bold;">function</span> handler<span style="color: #009900;">&#40;</span>location<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #003366; font-weight: bold;">var</span> message <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;message&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
message.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;&lt;img src='http://maps.google.com/staticmap?center=&quot;</span> <span style="color: #339933;">+</span> location.<span style="color: #660066;">coords</span>.<span style="color: #660066;">latitude</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;,&quot;</span> <span style="color: #339933;">+</span> location.<span style="color: #660066;">coords</span>.<span style="color: #660066;">longitude</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&amp;size=300x200&amp;maptype=hybrid&amp;zoom=16&amp;key=YOURGOOGLEAPIKEY' /&gt;&quot;</span><span style="color: #339933;">;</span>
message.<span style="color: #660066;">innerHTML</span><span style="color: #339933;">+=</span><span style="color: #3366CC;">&quot;&lt;p&gt;Longitude: &quot;</span> <span style="color: #339933;">+</span> location.<span style="color: #660066;">coords</span>.<span style="color: #660066;">longitude</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
message.<span style="color: #660066;">innerHTML</span><span style="color: #339933;">+=</span><span style="color: #3366CC;">&quot;&lt;p&gt;Latitude: &quot;</span> <span style="color: #339933;">+</span> location.<span style="color: #660066;">coords</span>.<span style="color: #660066;">latitude</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
message.<span style="color: #660066;">innerHTML</span><span style="color: #339933;">+=</span><span style="color: #3366CC;">&quot;&lt;p&gt;Accuracy: &quot;</span> <span style="color: #339933;">+</span> location.<span style="color: #660066;">coords</span>.<span style="color: #660066;">accuracy</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
navigator.<span style="color: #660066;">geolocation</span>.<span style="color: #660066;">getCurrentPosition</span><span style="color: #009900;">&#40;</span>handler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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>div id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;message&quot;</span><span style="color: #339933;">&gt;</span>Location unknown<span style="color: #339933;">&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></td></tr></table></div>

<p>The results:</p>

<a href='http://blog.bemoko.com/2009/06/17/iphone-30-geolocation-javascript-api/iphone-geo-2211/' title='iPhone OS 2.2.1'><img width="150" height="150" src="http://blog.bemoko.com/wp-content/uploads/2009/06/iphone-geo-2211-150x150.jpg" class="attachment-thumbnail" alt="iPhone OS 2.2.1" title="iPhone OS 2.2.1" /></a>
<a href='http://blog.bemoko.com/2009/06/17/iphone-30-geolocation-javascript-api/iphone-geo-300-1/' title='iPhone 3.0'><img width="150" height="150" src="http://blog.bemoko.com/wp-content/uploads/2009/06/iphone-geo-300-1-150x150.jpg" class="attachment-thumbnail" alt="iPhone 3.0" title="iPhone 3.0" /></a>
<a href='http://blog.bemoko.com/2009/06/17/iphone-30-geolocation-javascript-api/iphone-geo-300-2/' title='iPhone 3.0 - I am here!'><img width="150" height="150" src="http://blog.bemoko.com/wp-content/uploads/2009/06/iphone-geo-300-2-150x150.jpg" class="attachment-thumbnail" alt="iPhone 3.0 - I am here!" title="iPhone 3.0 - I am here!" /></a>

<p>Try it for yourself by pointing your Safari browser at <a href="http://bemoko.com/blog/iphonegeo">http://bemoko.com/blog/iphonegeo</a>.</p>
<p>Update 27/7/2009: I noticed the zoom level on the google static map <a href="http://code.google.com/apis/maps/documentation/staticmaps/">API</a> wasn&#8217;t being set so the map was zoomed all the way out. I&#8217;ve added a default zoom for the demo code above. Not sure if thats a new requirement from Google&#8217;s side?</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.bemoko.com%2F2009%2F06%2F17%2Fiphone-30-geolocation-javascript-api%2F&amp;title=iPhone%203.0%20geolocation%20javascript%20API&amp;bodytext=With%20the%20iPhone%203.0%20firmware%20released%20today%2C%20I%20thought%20I%27d%20show%20you%20how%20to%20access%20one%20of%20the%20features%20I%27ve%20been%20most%20looking%20forward%20to%20-%20support%20for%20the%20geolocation%20API%20in%20Safari%20means%20I%20can%20now%20create%20location%20aware%20websites.%0D%0A%0D%0AThis%20will%20be%20just%20a" title="Digg"><img src="http://blog.bemoko.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://sphinn.com/index.php?c=post&amp;m=submit&amp;link=http%3A%2F%2Fblog.bemoko.com%2F2009%2F06%2F17%2Fiphone-30-geolocation-javascript-api%2F" title="Sphinn"><img src="http://blog.bemoko.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fblog.bemoko.com%2F2009%2F06%2F17%2Fiphone-30-geolocation-javascript-api%2F&amp;title=iPhone%203.0%20geolocation%20javascript%20API&amp;notes=With%20the%20iPhone%203.0%20firmware%20released%20today%2C%20I%20thought%20I%27d%20show%20you%20how%20to%20access%20one%20of%20the%20features%20I%27ve%20been%20most%20looking%20forward%20to%20-%20support%20for%20the%20geolocation%20API%20in%20Safari%20means%20I%20can%20now%20create%20location%20aware%20websites.%0D%0A%0D%0AThis%20will%20be%20just%20a" title="del.icio.us"><img src="http://blog.bemoko.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.bemoko.com%2F2009%2F06%2F17%2Fiphone-30-geolocation-javascript-api%2F&amp;t=iPhone%203.0%20geolocation%20javascript%20API" title="Facebook"><img src="http://blog.bemoko.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fblog.bemoko.com%2F2009%2F06%2F17%2Fiphone-30-geolocation-javascript-api%2F&amp;title=iPhone%203.0%20geolocation%20javascript%20API" title="Mixx"><img src="http://blog.bemoko.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fblog.bemoko.com%2F2009%2F06%2F17%2Fiphone-30-geolocation-javascript-api%2F&amp;title=iPhone%203.0%20geolocation%20javascript%20API&amp;annotation=With%20the%20iPhone%203.0%20firmware%20released%20today%2C%20I%20thought%20I%27d%20show%20you%20how%20to%20access%20one%20of%20the%20features%20I%27ve%20been%20most%20looking%20forward%20to%20-%20support%20for%20the%20geolocation%20API%20in%20Safari%20means%20I%20can%20now%20create%20location%20aware%20websites.%0D%0A%0D%0AThis%20will%20be%20just%20a" title="Google Bookmarks"><img src="http://blog.bemoko.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.bemoko.com/2009/06/17/iphone-30-geolocation-javascript-api/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
	</channel>
</rss>

