2015-10-07 72 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

只需使用核心位置的当前位置,并开始,没有结束,虽然需要