我用这段代码做到了:
- (void) openBrowser:(id)sender
{
NSString *launchUrl=@"";
launchUrl= [launchUrl stringByAppendingString:@"http://maps.google.com/maps?daddr="];
NSString *tmpLat = [[NSString alloc] initWithFormat:@"%g", self.newRegion.center.latitude];
NSString *tmpLong = [[NSString alloc] initWithFormat:@"%g", self.newRegion.center.longitude];
NSString *llat=[tmpLat stringByAppendingString:[@"," stringByAppendingString:tmpLong]];
launchUrl=[@"http://maps.google.com/maps?daddr=" stringByAppendingString:llat];
launchUrl=[launchUrl stringByAppendingString:[@"&saddr=" stringByAppendingString:@"Current Location"]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[launchUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
}
openBrowser
是我使用详细信息披露按钮调用的方法。maps.google.com
我发现手机上安装的谷歌地图应用程序默认处理指向的网址;对于从 A 点到 B 点的路线,网址必须类似于:
http://maps.google.com/maps?daddr=whatever&saddr=whatever
daddr=目的地
saddr= 来源