在iOS 6.0中立即打开Apple Maps并从当前位置开始路由到主页 [英] Open Apple Maps and Start Route from Current Location to Home Immediately in iOS 6.0

查看:125
本文介绍了在iOS 6.0中立即打开Apple Maps并从当前位置开始路由到主页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程序中创建一个基本上标记为带我回家的链接。按下时,我希望它打开Apple Maps,从当前位置路由到家,然后开始轮流导航。

I'm wanting to create a link in my application that essentially will be labelled "Take Me Home". When pressed, I want it to open Apple Maps, route from current location to home, and start turn by turn navigation.

我找到了这个方案,但它没有做我希望的一切:

I have found this scheme, but it does not do everything I was hoping for:

http://maps.apple.com/maps?saddr=%f,%f&daddr=%f,%f


推荐答案

这是一个使用路线打开地图的工作代码(包括显示iOS5谷歌地图的选项)

Here is a working code for opening Maps with routes (including the option to show Google maps for iOS5)

-(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]];
}
}

这篇关于在iOS 6.0中立即打开Apple Maps并从当前位置开始路由到主页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆