请不要在未阅读整个问题的情况下将其标记为重复
在 iOS 中不显示 map 的情况下,有没有办法获取两个 CLLocation
点之间的自驾路线的长度?
绝非乌鸦飞过!!!但是就像在MK驾驶模式下
我不能使用谷歌,因为我必须在谷歌地图上显示结果。
我找到了这段代码,但这只在显示 iOS map 时有效:
-(void)showMapRouteFromCurrentLocation
{
CLLocationCoordinate2D currentUserCoordinate = YourCoordinate;
//currentUserCoordinate.latitude= +53.509980;
//currentUserCoordinate.longitude = -0.133700;
MKPlacemark *place = [[MKPlacemark alloc]
initWithCoordinate:currentUserCoordinate
addressDictionary:nil];
MKMapItem *mapItem = [[MKMapItem alloc]initWithPlacemark:place];
NSDictionary *routeOption = [[NSDictionary alloc] initWithObjectsAndKeys:MKLaunchOptionsDirectionsModeDriving,MKLaunchOptionsDirectionsModeKey, nil];
[mapItem openInMapsWithLaunchOptions:routeOption];
}
但这不是我需要的。
最佳答案
正如 brainray 所说,从 iOS7 开始,您可以执行以下操作:
MKDirectionsRequest *routeRequest = [[MKDirectionsRequest alloc] init];
routeRequest.transportType = MKDirectionsTransportTypeAutomobile;
[routeRequest setSource:startPoint]; // startPoint is an MKMapItem with the starting lat/long coordinate
[routeRequest setDestination :endPoint]; // endPoint an MKMapItem with the ending lat/long coordinate
MKDirections *routeDirections = [[MKDirections alloc] initWithRequest:routeRequest];
[routeDirections calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse * routeResponse, NSError *routeError)
{
// Check for error and then do something with the route...
MKRoute *route = routeResponse.routes[0];
}];
关于iOS:获取位置之间的距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15528565/