Mah*_*abu 5 cocoa-touch google-maps objective-c core-location ios
我需要使用Google maps 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]];
}
Run Code Online (Sandbox Code Playgroud)
但是我无法获得多条路线.
我是新手使用Google Maps API; 我按照本教程.
我怎样才能做到这一点?任何人都可以发布一些示例代码或教程吗?
alternative(可选),如果设置为true,则指定Directions服务可以在响应中提供多个路由备选.请注意,提供路由选择可能会增加服务器的响应时间.
您需要添加查询链接alternatives = true
| 归档时间: |
|
| 查看次数: |
2951 次 |
| 最近记录: |