方向API - 火车站之间的路由包括不必要的方向

时间:2017-08-04 11:36:29

标签: google-maps map-directions google-maps-direction-api

我目前正在使用Google Maps Directions API(网络服务)在火车站之间路由,但我发现结果包括步行路线,尽管起点和终点都是连接火车站。

例如,如果我从伯明翰国际(英国)和伦敦尤斯顿(路易斯安那)通过直接路线连接,我会得到结果:

Birmingham International to London Euston

请注意,搜索正在使用地点ID,并且两个地点ID都被称为火车站,因此Google知道原点和目的地都是电台,而不仅仅是街道地址。

如果我将伯明翰国际机场交给没有连接的国王十字车站:

Birmingham International to Kings Cross

最后一步是正确的,你需要从Euston步行到Kings Cross,但第一步是不正确的,因为原点地址ID已经是火车站。

我有什么东西在这里失踪吗?我想保持步行方向和第二个例子一样,但是第一个例子应该只有一步,因为起点和终点都是火车站。

提前干杯。

1 个答案:

答案 0 :(得分:0)

这是我上面发布的图片的完整代码

<?php
/*
//Birmingham Int to Euston (Direct Route)
$searchURLJSON = file_get_contents('https://maps.googleapis.com/maps/api/directions/json?origin=place_id:ChIJE3Z8xJq8cEgRCtDfBcX984c&destination=place_id:ChIJmxO_XDwbdkgR-zjbcc_J6Xs&mode=transit&key='.$googleMapsAPI);

//Birmingham Int to Kings Cross (Indirect Route)
$searchURLJSON = file_get_contents('https://maps.googleapis.com/maps/api/directions/json?origin=place_id:ChIJE3Z8xJq8cEgRCtDfBcX984c&destination=place_id:ChIJNVch-SMbdkgRqv1PBlyKQqU&mode=transit&key='.$googleMapsAPI);
*/

$searchURLJSON = file_get_contents('https://maps.googleapis.com/maps/api/directions/json?origin=place_id:ChIJE3Z8xJq8cEgRCtDfBcX984c&destination=place_id:ChIJmxO_XDwbdkgR-zjbcc_J6Xs&mode=transit&key='.$googleMapsAPI);
//$searchURLJSON = file_get_contents('https://maps.googleapis.com/maps/api/directions/json?origin=place_id:ChIJE3Z8xJq8cEgRCtDfBcX984c&destination=place_id:ChIJNVch-SMbdkgRqv1PBlyKQqU&mode=transit&key='.$googleMapsAPI);

$searchURL = json_decode($searchURLJSON);
print_r("<pre>");
print_r("<p>");
print_r("From: ".$searchURL->routes[0]->legs[0]->start_address." (id: ".$searchURL->geocoded_waypoints[0]->place_id.")<br />");
print_r("Types: ");
foreach(($searchURL->geocoded_waypoints[0]->types) as $type){
    print_r($type.", ");
}
print_r("</p><p>");
print_r("To: ".$searchURL->routes[0]->legs[0]->end_address." (id: ".$searchURL->geocoded_waypoints[1]->place_id.")<br />");
print_r("Types: ");
foreach(($searchURL->geocoded_waypoints[1]->types) as $type){
    print_r($type.", ");
}
print_r("</p>");
print_r("<h1>Route</h1>");
foreach(($searchURL->routes[0]->legs[0]->steps) as $step){
    print_r("<p>");
    print_r("(".$step->travel_mode.") ");
    print_r($step->html_instructions);
    print_r("</p>");
}
print_r("</pre>");
?>