<?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>MacOSCoders &#187; Google Maps</title>
	<atom:link href="http://www.macoscoders.com/tag/google-maps/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.macoscoders.com</link>
	<description>My blog to talk on iPhone, Mac OS, Adobe Flex, AIR...</description>
	<lastBuildDate>Mon, 16 Aug 2010 10:45:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Launch iPhone Maps application from within your Code</title>
		<link>http://www.macoscoders.com/2009/03/26/launch-iphone-maps-application-from-within-your-code/</link>
		<comments>http://www.macoscoders.com/2009/03/26/launch-iphone-maps-application-from-within-your-code/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 09:15:27 +0000</pubDate>
		<dc:creator>Anish Kumar</dc:creator>
				<category><![CDATA[iPhone Development]]></category>
		<category><![CDATA[iPhone SDK]]></category>
		<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[IPhone]]></category>

		<guid isPermaLink="false">http://www.macoscoders.com/?p=50</guid>
		<description><![CDATA[Last week I spent some time playing around with the Maps application on the iPhone and I thought I’d share some of my findings. (Note that since there is no maps application available in the iPhone simulator all of the below will be launched in Safari instead &#8211; you’ll have to actually run it on [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I spent some time playing around with the Maps application on the iPhone and I thought I’d share some of my findings. (Note that since there is no maps application available in the iPhone simulator all of the below will be launched in Safari instead &#8211; you’ll have to actually run it on your iPhone to see it in the maps application.)</p>
<p><span id="more-50"></span>In it’s simplest form, to launch the maps application at your last location:</p>
<div style="margin-left: 10px;"><code><br />
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"<span style="color: red;">http://maps.google.com/maps</span>"]];<br />
</code></div>
<p>which gives you something like this:</p>
<p><img style="border: 0pt none;" src="http://macoscoders.com/images/maps1.jpg" border="0" alt="" width="320" height="480" /></p>
<p>Getting slightly more interesting, we can specify the <strong>latitude/longitude</strong> (”<strong>ll</strong>“) flag to tell the maps application to launch at a specific location (in this case, my workplace):</p>
<div style="margin-left: 10px;"><code><br />
NSString *latlong = @"-33.874559,151.219575";</code></p>
<p>NSString *url = [NSString stringWithFormat: @"<span style="color: red;">http://maps.google.com/maps?ll=%@</span>",<br />
[latlong stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];</p>
<p>[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];</p></div>
<p>results in:</p>
<p><img style="border: 0pt none;" src="http://macoscoders.com/images/maps2.jpg" border="0" alt="" width="320" height="480" /></p>
<p>If you want to get maps to show all the thai restaurants near you, you can specify the <strong>query</strong> (”<strong>q</strong>“) flag:</p>
<div style="margin-left: 10px;"><code><br />
NSString *name = @"thai";</code></p>
<p>NSString *latlong = @”-33.874559,151.219575″;</p>
<p>NSString *url = [NSString stringWithFormat: @"<span style="color: red;">http://maps.google.com/maps?q=%@&amp;mrt=yp&amp;ll=%@</span>",<br />
[name stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],<br />
[latlong stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];<br />
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];</div>
<p>will give you:</p>
<p><img style="border: 0pt none;" src="http://macoscoders.com/images/maps3.jpg" border="0" alt="" width="320" height="480" /></p>
<p>Note that in this example, I’ve include the <strong>search mode</strong> (”<strong>mrt</strong>“) flag, with a value of “<strong>yp</strong>” &#8211; this tells maps to search only for businesses &#8211; although this is of course not necessary.</p>
<p>Other interesting parameters include the <strong>zoom</strong> (”<strong>z</strong>“) flag zoom-level (1-19 defaults is 17 I believe &#8211; maps will intelligently alter the zoom level if you specify a query):</p>
<div style="margin-left: 10px;"><code><br />
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"<span style="color: red;">http://maps.google.com/maps?z=8</span>"]];<br />
</code></div>
<p>zooms out from the previous map:</p>
<p><img style="border: 0pt none;" src="http://macoscoders.com/images/maps4.jpg" border="0" alt="" width="320" height="480" /></p>
<p>and the ability to change the map type using the map type (”t”) flag (options are “m”-map, “k”-satellite, “h”- hybrid):</p>
<div style="margin-left: 10px;"><code><br />
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"<span style="color: red;">http://maps.google.com/maps?t=k</span>"]];<br />
</code></div>
<p>shows the map in satellite mode:</p>
<p><img style="border: 0pt none;" src="http://macoscoders.com/images/maps5.jpg" border="0" alt="" width="320" height="480" /></p>
<p>Last, but certainly not least &#8211; it’s actually possible to get the maps application to show with your own set of pins dropped on it (rather than using google’s search results as above). In order to do this, you will need to provide a KML file (KML &#8211; “Keyhole Markup Language” is a standard for representing geographic annotation &#8211; more information can be found <a href="http://en.wikipedia.org/wiki/KML">here</a>).</p>
<p>This is again done using the <strong>query</strong>(”<strong>q</strong>“) flag, but this time you pass in the url of your KML file:</p>
<div style="margin-left: 10px;"><code><br />
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"<span style="color: red;">http://maps.google.com/maps?q=http://http://www.macoscoders.com/images/sample.kml</span>"]];<br />
</code></div>
<p>(in this example, I only have a single entry in my KML file &#8211; you can view the file here: <a href="http://objective-d.com/sample.kml">http://<code><span style="color: red;">www.macoscoders.com/images</span></code>/sample.kml</a>):</p>
<p><img style="border: 0pt none;" src="http://macoscoders.com/images/maps6.jpg" border="0" alt="" width="320" height="480" /></p>
<p>This has just been a taster of the kind of control you have over the maps application, but hopefully it’s got you interested enough to start playing around.</p>
<p>For more information I suggest you check out the handy reference available here: <a href="http://mapki.com/index.php?title=Google_Map_Parameters">http://mapki.com/index.php?title=Google_Map_Parameters</a>.</p>
<p>If you are interested in including a map from <strong>within</strong> your iPhone applications, I encourage you to take a look at the <a href="http://code.google.com/p/iphone-google-maps-component/">iphone-google-maps-component</a> and <a href="http://code.google.com/p/route-me/">route-me</a> projects.</p>
<p><strong>[Update]:</strong> The iPhone 2.2. update seems to have broken url’s in the form: maps://maps.google.com/maps?q= however in my initial testing, it seems if you use http://maps.google.com/maps?q= (i.e. using http:// instead of maps://) then things still seem to function correctly &#8211; I’ve updated the post to reflect this.</p>
<div id="wherego_related"> </div>]]></content:encoded>
			<wfw:commentRss>http://www.macoscoders.com/2009/03/26/launch-iphone-maps-application-from-within-your-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
