4

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

我找到了这个方案,但它并没有完成我所希望的一切:

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

2 回答 2

5

这是打开带有路线的地图的工作代码(包括显示适用于 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]];
}
}
于 2013-05-27T11:48:43.170 回答
0

使用这个对我来说它工作正常::

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]];
于 2016-05-10T11:27:46.990 回答