0

Im trying to get some transit suggestions using google maps API directions:

https://maps.googleapis.com/maps/api/directions/json?origin=Hauptbahnhof+M%C3%BCnchen&destination=Pasing,%2081241&mode=transit&transit_mode=train|tram|subway&key=MY(private)API

but google returns me only one closest bus/train. Is there any way that I get at least 3 closest suggestions about how to get to defined point?

My response looks so: Only one train

                 "start_location" : {
                    "lat" : 48.12606599999999,
                    "lng" : 11.663375
                 },
                 "transit_details" : {
                    "arrival_stop" : {
                       "location" : {
                          "lat" : 48.149852,
                          "lng" : 11.461872
                       },
                       "name" : "München-Pasing"
                    },
                    "arrival_time" : {
                       "text" : "20:31",
                       "time_zone" : "Europe/Berlin",
                       "value" : 1511033460
                    },
                    "departure_stop" : {
                       "location" : {
                          "lat" : 48.12606599999999,
                          "lng" : 11.663375
                       },
                       "name" : "München-Trudering"
                    },
                    "departure_time" : {
                       "text" : "20:03",
                       "time_zone" : "Europe/Berlin",
                       "value" : 1511031780
                    },
                    "headsign" : "Geltendorf",
                    "line" : {
                       "agencies" : [
                          {
                             "name" : "Deutsche Bahn AG",
                             "url" : "http://www.bahn.de/"
                          }
                       ],
                       "short_name" : "S4",
                       "vehicle" : {
                          "icon" : "//maps.gstatic.com/mapfiles/transit/iw2/6/rail2.png",
                          "local_icon" : "//maps.gstatic.com/mapfiles/transit/iw2/6/de-sbahn.png",
                          "name" : "S-Bahn",
                          "type" : "COMMUTER_TRAIN"
                       }
                    },
                    "num_stops" : 13
                 },
                 "travel_mode" : "TRANSIT"

I also getting walking instruction. Honestly I would like to get only bus|subway|train directions ;)

I would be very appreciate if someone smart could give me a clue :)

Anna K
  • 1,666
  • 4
  • 23
  • 47

1 Answers1

2

Per the documentation: set &alternatives=true

Optional parameters

alternatives — 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.

https://maps.googleapis.com/maps/api/directions/json?origin=Hauptbahnhof+M%C3%BCnchen&destination=Pasing,%2081241&mode=transit&transit_mode=train|tram|subway&alternatives=true&key=MY(private)API

returns 4 results for me.

Community
  • 1
  • 1
geocodezip
  • 158,664
  • 13
  • 220
  • 245