【问题标题】:Find the number of routes between two places查找两地之间的路线数
【发布时间】:2011-08-31 00:38:46
【问题描述】:

我需要使用 Google 地图 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

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

【问题讨论】:

  • 如果我能在 google 中找到答案,那么我不会在这个论坛中提出问题,我没有通过谷歌搜索找到它,那么只有我在这个论坛中提出问题。我没有不明白为什么这些人对我的问题投了反对票。

标签: objective-c cocoa-touch ios google-maps core-location


【解决方案1】:

替代品(可选),如果设置为 true,指定方向 服务可能提供不止一个 响应中的路线替代方案。 请注意,提供路线选择 可能会增加响应时间 服务器。

来自The Google Directions API

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

【讨论】:

  • 非常感谢 Terente lonut Alexandru,但我确实发现它有任何变化。我在哪里可以获得多条路线。如何显示它们。
【解决方案2】:

要获得多条路线,您必须使用standard google direction api。通过此 api,您可以根据您在 api 中选择的旅行模式,即驾车、步行或骑自行车(仅在美国提供自行车路线)获得不同的路线 例如:http://maps.googleapis.com/maps/api/directions/xml?origin=srcLatitude,srcLongitude&destination=destLatitude,destLongitude&mode=driving&sensor=false
在这里您可以给出源和目的地的经纬度,并将模式参数的值更改为驾驶、步行或骑自行车以获得多条路线。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-13
    • 2011-10-10
    • 2010-11-03
    • 2011-08-08
    • 2011-01-02
    • 2010-12-05
    相关资源
    最近更新 更多