2015-10-07 26 views
1

我想要做的就是允許用戶打開Apple Maps並讓它自動打開Directions表單,以便他們獲取我的位置的路線。在打開Apple Maps時向目標地址添加標籤

目的地是緯度/經度對。我這樣做:

NSString *addressString = @"http://maps.apple.com/?daddr=50.894967,4.341626&dirflg=d"; 
NSURL *url = [NSURL URLWithString:addressString]; 
[[UIApplication sharedApplication] openURL:url]; 

這將打開Apple Maps,如我所料。但是,在目標字段中,它會顯示經緯度對。我想指定這個標籤。這裏是我的意思是:

enter image description here

反正我有可以替換使用網址參數標籤的座標?

謝謝!

+0

對不起,我真的不明白要實現。你能解釋一下嗎? – joern

+0

@joern在截圖中,「End:」字段自動填充爲「50.894967,4.341626」,但我希望能夠指定一些其他文本以進入此字段(我正在導航用戶的位置的名稱) – user1282637

回答

0

這可能不是你想要的方式。但它給了我們更多的靈活性來打開地圖應用程序。這是使用[MKMapItem openMapsWithItems:launchOptions:]來要求地圖打開地址。屏幕看起來有點不同於你所期望的。

CLLocation* location = [[CLLocation alloc] initWithLatitude:50.894967 longitude:4.341626]; 
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location.coordinate, 10000, 10000); 
NSDictionary *addressDict = @{ 
     (NSString *) kABPersonAddressStreetKey : @"Any Name", 
}; 
MKPlacemark *destinationPlacemark = [[MKPlacemark alloc] initWithCoordinate:location.coordinate addressDictionary:addressDict]; 
MKMapItem *destinationMapItem = [[MKMapItem alloc] initWithPlacemark:destinationPlacemark]; 

[destinationMapItem openInMapsWithLaunchOptions:@{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving}]; 

[MKMapItem openMapsWithItems:@[destinationMapItem] 
       launchOptions:@{ 
         MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving, 
         MKLaunchOptionsMapSpanKey : [NSValue valueWithMKCoordinateSpan:region.span] 
       } 
]; 

enter image description here

0

只需使用核心位置的當前位置,並開始,沒有結束,雖然需要