Linking to Google Maps app

500 views
Skip to first unread message

bfeist

unread,
Sep 8, 2008, 11:19:11 AM9/8/08
to phonegap
Hi All,

Phonegap looks like just what the doctor ordered. Having a small issue
though:

A link to google maps within iPhone Safari automatically links to the
iphone maps app (very handy). However, when clicking the same link
within Phonegap's UIWebView object, it actually loads the google maps
website within the UIWebView.

I want the link to open the maps app. Is there a specific call that I
can use? Any help is greatly appreciated.

Ben

bfeist

unread,
Sep 11, 2008, 10:09:57 AM9/11/08
to phonegap
Alright, no response so I built this myself. I don't think I'll add it
to the base project source repository due to all the changes I made,
but the detail of what I did is below.

Approach:
iPhone 2.0+ uses a different URL method to open maps in the map app
than iPhone 1.0+ did
old: http://maps.google.com/q=<query string>
new: maps:q=<query string>
Safari intercepts these calls and opens the maps app. Unfortunately a
UIWebView does NOT (thank you Apple)

I changed the GlassAppDeligate.m file to accept a new directive called
"openmap" that would take a "q=<query string>" parameter and create a
call to safari in the form "maps:q=<query string>"

I added the appropriate hooks in gap.js to pass the openmap directive
through Device.Map.open("string").


Code Changes:
JS:
I had to change gap.js to delimit commands by "::" instead of ":" due
to "http://" type urls interfering with the command delimiting (this
is needed when loading KML files into the maps app)

Added the following JS code to the Device function:
Map: {
// available: true,

lon: null,
lat: null,
callback: null,

open: function(url) {
Device.exec("openmap::" + url);
}

},


Objective-C:
Changed GlassAppDeligate.m to delimit commands by "::" as well (see
above)

Code added to GlassAppDeligate.m (- (bool)webView... method) below
the vibration stuff.

//Google maps call
else if([(NSString *)[parts objectAtIndex:1]
isEqualToString:@"openmap"]) {
NSLog(@"Map request!");
NSLog([parts objectAtIndex:2]);

NSString *mapurl = [@"maps:" stringByAppendingString:[parts
objectAtIndex:2]];
NSLog(mapurl);
[[UIApplication sharedApplication] openURL:[NSURL
URLWithString:mapurl]]; //use safari to launch google maps url, which
redirects to google app
}
Reply all
Reply to author
Forward
0 new messages