2012-08-15 72 views
0

我正在开发一个iOS应用程序。在这个应用程序中,我有一种类型的视图,其中包括其他信息呈现MKMapView地图到当前选定的公司商店;商店的位置通过一个图钉在地图上绘制出来。该针有一个自定义的MKAnnotationView,我在其中添加了一个详细披露按钮。我想要做的是,当用户按下按钮,提出一些选择的弹出式广告 - 就像去特定商店的网站一样。导航到MKMapView上的注释位置

我想实现的选项之一是从用户的当前位置导航到商店的位置。我想要应用程序要做的是提供一个应该说史密斯的提示。比如“导航到位置”,点击后打开Goog​​leMaps,选择导航到位置选项,选择CurrentLocation作为“开始”,商店的位置存储在引脚的坐标中作为“结束”。可以这样做,因为我还没有找到解决办法呢?如果是这样,怎么样?

+0

看一看http://stackoverflow.com/问题/ 30058/how-can-i-launch-the-google-maps-iphone-application-from-within-my-own-native-ap并找出需要为您的操作提供哪些参数。 – anka 2012-08-15 11:36:19

+0

还可以查看https://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/MapLinks.html – anka 2012-08-15 11:38:00

回答

2

我与此代码做到了:

- (void) openBrowser:(id)sender 
{ 
    NSString *[email protected]""; 
    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的网址默认由安装在手机上的Google地图应用处理; 从A点到B点方向url必须是这样的:

http://maps.google.com/maps?daddr=whatever&saddr=whatever

DADDR =目标

SADDR =来源