2017-08-04 91 views
0

我目前使用Google Maps Directions API(网络服务)在火车站之间进行路线选择,但我发现尽管起点和目的地都连接了火车站。路线API - 火车站之间的路由包括不必要的路线

例如,如果从伯明翰国际(英国)和伦敦Euston我的路线,它们通过直连路由都连接,我得到的结果:

Birmingham International to London Euston

注意,搜索使用的地方做身份证和两个地方的身份证都被列为火车站,所以Google知道,出发地和目的地都是车站,而不仅仅是街道地址。

如果我做伯明翰INTERNATION Kings Cross火车站未连接:

Birmingham International to Kings Cross

的最后一步是在正确的,你需要从尤斯顿步行到国王十字,但第一步由于出发地ID已经是火车站,因此不正确。

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

提前欢呼。

+0

你说得对张贴的图片完整的代码,这些都是非常愚蠢的步行路线。你能显示你的路线请求代码吗?它必须能够用一些逻辑来过滤掉它们 –

+1

它看起来像来源地ID代表到火车站的接入点,所以步行部分似乎是预期的。在Directions计算器中查看此路线:https://directionsdebug.firebaseapp.com/?origin=place_id%3AChIJE3Z8xJq8cEgRCtDfBcX984c&destination=place_id%3AChIJmxO_XDwbdkgR-zjbcc_J6Xs&mode=transit。 Probaly Directions API始终考虑接入点并提供步行路线。 – xomena

+0

是的,确切地说。 如果起点为ChIJE3Z8xJq8cEgRCtDfBcX984c,那么我们得到这个 https://ibb.co/nrCDEv 如果原产地是第二点的路由中的位置(纬度:52.450676,经度:-1.725229),然后它看起来像这样 https://ibb.co/buZ4Ma –

回答

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>"); 
?>