gpt4 book ai didi

objective-c - 查找两地之间的路线数

转载 作者:可可西里 更新时间:2023-11-01 04:40:35 25 4
gpt4 key购买 nike

我需要使用 Google map API 找出从源头到目的地的路线数量,然后找出其中最短路线。

我可以通过使用此代码获得一条路线

-(NSArray*) calculateRoutesFrom:(CLLocationCoordinate2D) f to: (CLLocationCoordinate2D) t {
NSString* saddr = [NSString stringWithFormat:@"%f,%f", f.latitude, f.longitude];
NSString* daddr = [NSString stringWithFormat:@"%f,%f", t.latitude, t.longitude];

NSString* apiUrlStr = [NSString stringWithFormat:@"http://maps.google.com/maps?output=dragdir&saddr=%@&daddr=%@", saddr, daddr];
NSURL* apiUrl = [NSURL URLWithString:apiUrlStr];
NSLog(@"api url: %@", apiUrl);
NSString *apiResponse = [NSString stringWithContentsOfURL:apiUrl];
NSString* encodedPoints = [apiResponse stringByMatching:@"points:\\\"([^\\\"]*)\\\"" capture:1L];

return [self decodePolyLine:[encodedPoints mutableCopy]];
}

但我无法获得多条路线。

我刚开始使用 Google Maps API;我关注了this tutorial .

我该怎么做?任何人都可以发布一些示例代码或教程吗?

最佳答案

alternatives (optional), if set to true, specifies that the Directions service may provide more than one route alternative in the response. Note that providing route alternatives may increase the response time from the server.

来自 The Google Directions API

您需要在查询链接中添加 alternatives=true

关于objective-c - 查找两地之间的路线数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6095435/

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