找出两个地方之间的路线数 [英] Find the number of routes between two places

查看:144
本文介绍了找出两个地方之间的路线数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要找出使用Google maps API从来源到目的地的路线数量,然后找出哪一条路线是最短的路线。

I need to find out the number of routes from a source to a destination using the Google maps API, and then find, among those, which one is the shortest route.

我可以使用此代码获得一个路由

I am able to get one route by using this code

-(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]];
}



<

but I'm unable to get multiple routes.

我是第一次使用Google Maps API;我按照本教程

I'm new to using the Google Maps API; I followed this tutorial.

一个请张贴一些示例代码或教程?

How can I do this? Can any one please post some sample code or a tutorial?

推荐答案



true,指定Directions
服务可能在响应中提供多个
路由选择。
请注意,提供路由替换
可能会增加响应时间从
服务器。

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.

Google Directions API

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

You need to add in your query link alternatives=true

这篇关于找出两个地方之间的路线数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆