UIWebView href to open Map application failing
I have a UIWebView with a link as follows:
<a href="maps:saddr=Current Location&daddr=Some place on Earth@38.043316,-120.397757">Get Directions</a>
Within Safari Mobile this link works just fine and opens the Map app with current location to lat/lon directions, but inside of my iPhone app in a UIWebView it results in this error:
didFailLoadWithError:Error Domain=WebKitErrorDomain Code=101 "The URL can't be shown"
I have added the following code to my shouldStartLoadWithRequest which checks for non-standard schemes and tries to launch it using the interna开发者_运维百科l app:
if (![url.scheme isEqual:@"http"] && ![url.scheme isEqual:@"https"] ) {
if ([[UIApplication sharedApplication]canOpenURL:url]){
[[UIApplication sharedApplication]openURL:url];
return NO;
}
}
return YES;
What could I be doing wrong? This used to work in prior iOS versions.
The correct URL no longer starts with "maps". Instead use "http". You also need to specify the google servers.
Here is a link to the relevant docs: Map Links
In your case it would look something like this:
http://maps.google.com/maps?saddr=Current Location?daddr=Some place on Earth@38.043316,-120.397757
Please note that this code is not tested as I am not near my development machine right now.
精彩评论