0

I'm currently using Google Maps Directions API (Web Services) to route between train stations but I'm finding the results include walking directions despite both origin and destination being connected railway stations.

For example, if I route from Birmingham International (UK) and London Euston which are both connected via direct routes, I get the results:

Birmingham International to London Euston

Note that the search was doing using the place IDs and both place IDs are stated as being train stations, so Google knows that both the origin and destination are stations and not just street addresses.

If I do Birmingham Internation to Kings Cross Station which aren't connected:

Birmingham International to Kings Cross

The last step is correct in that you would need to walk from Euston to Kings Cross, but the first step is incorrect since the origin place ID is already the train station.

Is there something I'm missing here? I want to keep the walking directions as with the 2nd exmaple, but the first example should only have 1 step since both origin and destination are train station.

Cheers in advance.

GSephElec
  • 79
  • 1
  • 7
  • You're right, those are pretty stupid walking directions. Can you show the code of your route request? It must be possible to filter those out with some logic – Emmanuel Delay Aug 04 '17 at 11:59
  • 1
    It looks like the origin place ID represents an access point to the train station, so the walking part seems to be expected. Have a look at this route in the Directions calculator: https://directionsdebug.firebaseapp.com/?origin=place_id%3AChIJE3Z8xJq8cEgRCtDfBcX984c&destination=place_id%3AChIJmxO_XDwbdkgR-zjbcc_J6Xs&mode=transit. Probaly the Directions API always takes into account access points and provides walking directions. – xomena Aug 04 '17 at 19:17
  • Yes, exactly. If the origin is ChIJE3Z8xJq8cEgRCtDfBcX984c, then we get this https://ibb.co/nrCDEv If the origin is the location of the second point in the route (lat: 52.450676, lng: -1.725229), then it looks like this https://ibb.co/buZ4Ma – Anatolii Suhanov Aug 04 '17 at 21:03

1 Answers1

0

Here's my full code for the images posted above

<?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>");
?>
GSephElec
  • 79
  • 1
  • 7