Kir*_*met 4 iphone ios ios6 ios6-maps
我想在我的应用程序中创建一个基本上标记为"带我回家"的链接.按下时,我希望它打开Apple Maps,从当前位置路由到家,然后开始转弯导航.
我找到了这个方案,但它没有做我希望的所有事情:
http://maps.apple.com/maps?saddr=%f,%f&daddr=%f,%f
Run Code Online (Sandbox Code Playgroud)
以下是使用路线打开地图的工作代码(包括显示iOS5的Google地图的选项)
-(IBAction)showMapApp:(id)sender
{
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(self.location.latitude,self.location.longitude);
//create MKMapItem out of coordinates
MKPlacemark* placeMark = [[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil];
MKMapItem* destination = [[MKMapItem alloc] initWithPlacemark:placeMark];
if([destination respondsToSelector:@selector(openInMapsWithLaunchOptions:)])
{
//using iOS6 native maps app
if(_mode == 1)
{
[destination openInMapsWithLaunchOptions:@{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeWalking}];
}
if(_mode == 2)
{
[destination openInMapsWithLaunchOptions:@{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving}];
}
if(_mode == 3)
{
[destination openInMapsWithLaunchOptions:@{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving}];
}
} else{
//using iOS 5 which has the Google Maps application
NSString* url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=Current+Location&daddr=%f,%f", self.location.latitude, self.location.longitude];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4465 次 |
| 最近记录: |