4

アプリケーションに、基本的に「TakeMeHome」というラベルの付いたリンクを作成したいと思います。押すと、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 に答える