Apple Maps 및 IOS 6.0에서 현재 위치에서 현재 위치까지 경로를 시작하십시오.
문제
본질적으로 "집에 가져 가라"라는 레이블로 표시되는 내 응용 프로그램에서 링크를 만들고 싶습니다.누르면 Apple Maps, 현재 위치에서 홈으로의 경로를 열고 켜기 탐색을 시작합니다.
나는이 계획을 발견했지만, 내가 희망하는 모든 것을하지 않습니다 :
http://maps.apple.com/maps?saddr=%f,%f&daddr=%f,%f
. 해결책
다음은 경로가있는지도를 열기위한 작업 코드입니다 (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]];
}
}
. 다른 팁
이 작업을 수행합니다. 괜찮습니다 ::
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]];
. 제휴하지 않습니다 StackOverflow