gpt4 book ai didi

iOS:获取位置之间的距离

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:03:30 26 4
gpt4 key购买 nike

请不要在未阅读整个问题的情况下将其标记为重复

在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com