Open Apple Maps and Start Route from Current Location to Home Immediately in iOS 6.0

故事扮演 提交于 2019-12-07 10:08:24

问题


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

回答1:


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



回答2:


Use this For me its working fine::

NSString* url = [NSString stringWithFormat: @"http://maps.apple.com/maps?saddr=44.521358,11.374080&daddr=44.518640,11.362665"];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];


来源:https://stackoverflow.com/questions/12658826/open-apple-maps-and-start-route-from-current-location-to-home-immediately-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!