Search code examples
androidgoogle-mapsgoogle-directions-api

whats wrong in getting transit direction?


when I use this url to get driving direction , it gets me json correctly and it works properly :

http://maps.googleapis.com/maps/api/directions/json?origin=sourcelat,sourcelog&destination=destlat,destlog&sensor=false&mode=driving&alternatives=true

and when i want to get transit direction i use this url, but it does not work :

http://maps.googleapis.com/maps/api/directions/json?origin=sourcelat,sourcelog&destination=destlat,destlog&sensor=false&mode=transit&alternatives=true

can any one tell me whats my problem ? both source and destination are in Paris.


Solution

  • When requesting transit directions, one of departure_time or arrival_time must be specified. These times are expressed in seconds since midnight, January 1, 1970 UTC.

    The following URL requests transit directions from the Louvre to the Eiffel Tower departing at noon on Sunday, September 29, 2013. http://maps.googleapis.com/maps/api/directions/json?origin=48.8611,2.3364&destination=48.8582,2.2945&mode=transit&sensor=false&region=fr&departure_time=1380456000

    Here's the JSON response:

    {
       "routes" : [
          {
             "bounds" : {
                "northeast" : {
                   "lat" : 48.862972,
                   "lng" : 2.3367707
                },
                "southwest" : {
                   "lat" : 48.855014,
                   "lng" : 2.2890295
                }
             },
             "copyrights" : "Map data ©2013 Cybercity, Google",
             "legs" : [
                {
                   "arrival_time" : {
                      "text" : "2:37pm",
                      "time_zone" : "Europe/Paris",
                      "value" : 1380458251
                   },
                   "departure_time" : {
                      "text" : "2:00pm",
                      "time_zone" : "Europe/Paris",
                      "value" : 1380456000
                   },
                   "distance" : {
                      "text" : "4.9 km",
                      "value" : 4885
                   },
                   "duration" : {
                      "text" : "38 mins",
                      "value" : 2251
                   },
                   "end_address" : "Avenue Anatole France, 75007 Paris, France",
                   "end_location" : {
                      "lat" : 48.858329,
                      "lng" : 2.2946919
                   },
                   "start_address" : "Cour Carrée et Pyramide du Louvre, 75001 Paris, France",
                   "start_location" : {
                      "lat" : 48.8610339,
                      "lng" : 2.3367707
                   },
                   "steps" : [
                      {
                         "distance" : {
                            "text" : "1.1 km",
                            "value" : 1061
                         },
                         "duration" : {
                            "text" : "13 mins",
                            "value" : 809
                         },
                         "end_location" : {
                            "lat" : 48.860817,
                            "lng" : 2.325676
                         },
                         "html_instructions" : "Walk to Musée d'Orsay",
                         "polyline" : {
                            "points" : "mdfiHykgMh@P|At@@?@@?@?B?B}ApJCDC?CXIb@Id@vBfAXNFDFDFDGb@gAdIg@zDDNBNDT?@?B@B@B?BBB@B@?PN@@@@BH^V|AbAZTRt@ER[|ASz@KPEFEHELQd@_@bA[z@KXIXG\\a@pBS~@PJU|@"
                         },
                         "start_location" : {
                            "lat" : 48.8610339,
                            "lng" : 2.3367707
                         },
                         "steps" : [
                            {
                               "distance" : {
                                  "text" : "0.3 km",
                                  "value" : 275
                               },
                               "duration" : {
                                  "text" : "3 mins",
                                  "value" : 198
                               },
                               "end_location" : {
                                  "lat" : 48.8609596,
                                  "lng" : 2.3339723
                               },
                               "html_instructions" : "Head \u003cb\u003esouth\u003c/b\u003e on \u003cb\u003eCour Carrée et Pyramide du Louvre\u003c/b\u003e toward \u003cb\u003ePl. du Carrousel\u003c/b\u003e",
                               "polyline" : {
                                  "points" : "mdfiHykgMh@P|At@@?@@?@?B?B}ApJCDC?CXIb@Id@"
                               },
                               "start_location" : {
                                  "lat" : 48.8610339,
                                  "lng" : 2.3367707
                               },
                               "travel_mode" : "WALKING"
                            },
                            {
                               "distance" : {
                                  "text" : "0.1 km",
                                  "value" : 103
                               },
                               "duration" : {
                                  "text" : "1 min",
                                  "value" : 78
                               },
                               "end_location" : {
                                  "lat" : 48.8601075,
                                  "lng" : 2.3334357
                               },
                               "html_instructions" : "Turn \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003ePl. du Carrousel\u003c/b\u003e",
                               "maneuver" : "turn-left",
                               "polyline" : {
                                  "points" : "_dfiHizfMvBfAXNFDFDFD"
                               },
                               "start_location" : {
                                  "lat" : 48.8609596,
                                  "lng" : 2.3339723
                               },
                               "travel_mode" : "WALKING"
                            },
                            {
                               "distance" : {
                                  "text" : "0.2 km",
                                  "value" : 211
                               },
                               "duration" : {
                                  "text" : "3 mins",
                                  "value" : 171
                               },
                               "end_location" : {
                                  "lat" : 48.8607092,
                                  "lng" : 2.3306935
                               },
                               "html_instructions" : "Turn \u003cb\u003eright\u003c/b\u003e onto \u003cb\u003eQuai François Mitterrand\u003c/b\u003e",
                               "maneuver" : "turn-right",
                               "polyline" : {
                                  "points" : "u~eiH_wfMGb@gAdIg@zD"
                               },
                               "start_location" : {
                                  "lat" : 48.8601075,
                                  "lng" : 2.3334357
                               },
                               "travel_mode" : "WALKING"
                            },
                            {
                               "distance" : {
                                  "text" : "0.2 km",
                                  "value" : 170
                               },
                               "duration" : {
                                  "text" : "2 mins",
                                  "value" : 137
                               },
                               "end_location" : {
                                  "lat" : 48.8595728,
                                  "lng" : 2.3293037
                               },
                               "html_instructions" : "Slight \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003ePont Royal\u003c/b\u003e",
                               "maneuver" : "turn-slight-left",
                               "polyline" : {
                                  "points" : "mbfiHyefMDNBNDT?@?B@B@B?BBB@B@?PN@@@@BH^V|AbAZTRt@"
                               },
                               "start_location" : {
                                  "lat" : 48.8607092,
                                  "lng" : 2.3306935
                               },
                               "travel_mode" : "WALKING"
                            },
                            {
                               "distance" : {
                                  "text" : "71 m",
                                  "value" : 71
                               },
                               "duration" : {
                                  "text" : "1 min",
                                  "value" : 51
                               },
                               "end_location" : {
                                  "lat" : 48.8598405,
                                  "lng" : 2.3284286
                               },
                               "html_instructions" : "Turn \u003cb\u003eright\u003c/b\u003e onto \u003cb\u003eQuai Anatole France\u003c/b\u003e",
                               "maneuver" : "turn-right",
                               "polyline" : {
                                  "points" : "i{eiHc}eMER[|ASz@"
                               },
                               "start_location" : {
                                  "lat" : 48.8595728,
                                  "lng" : 2.3293037
                               },
                               "travel_mode" : "WALKING"
                            },
                            {
                               "distance" : {
                                  "text" : "0.2 km",
                                  "value" : 205
                               },
                               "duration" : {
                                  "text" : "2 mins",
                                  "value" : 140
                               },
                               "end_location" : {
                                  "lat" : 48.860707,
                                  "lng" : 2.325993
                               },
                               "html_instructions" : "Slight \u003cb\u003eright\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003eDestination will be on the left\u003c/div\u003e",
                               "maneuver" : "turn-slight-right",
                               "polyline" : {
                                  "points" : "_}eiHuweMKPEFEHELQd@_@bA[z@KXIXG\\a@pBS~@PJ"
                               },
                               "start_location" : {
                                  "lat" : 48.8598405,
                                  "lng" : 2.3284286
                               },
                               "travel_mode" : "WALKING"
                            },
                            {
                               "distance" : {
                                  "text" : "26 m",
                                  "value" : 26
                               },
                               "duration" : {
                                  "text" : "1 min",
                                  "value" : 34
                               },
                               "end_location" : {
                                  "lat" : 48.860817,
                                  "lng" : 2.325676
                               },
                               "polyline" : {
                                  "points" : "mbfiHmheMU|@"
                               },
                               "start_location" : {
                                  "lat" : 48.860707,
                                  "lng" : 2.325993
                               },
                               "travel_mode" : "WALKING"
                            }
                         ],
                         "travel_mode" : "WALKING"
                      },
                      {
                         "distance" : {
                            "text" : "3.2 km",
                            "value" : 3151
                         },
                         "duration" : {
                            "text" : "7 mins",
                            "value" : 442
                         },
                         "end_location" : {
                            "lat" : 48.855014,
                            "lng" : 2.289154
                         },
                         "html_instructions" : "Train towards Versailles - Château / Saint-Quentin / Chaville - Vélizy / Pontoise",
                         "polyline" : {
                            "points" : "ccfiHofeMVNgJpc@}@hGU|BIvBJrVFrN@tKPrZNpSBf@XlG~BtLpDlJlJnOtHrL|CzCnBp@zCrAxAz@FW"
                         },
                         "start_location" : {
                            "lat" : 48.860817,
                            "lng" : 2.325676
                         },
                         "transit_details" : {
                            "arrival_stop" : {
                               "location" : {
                                  "lat" : 48.855014,
                                  "lng" : 2.289154
                               },
                               "name" : "Champ de Mars - Tour Eiffel"
                            },
                            "arrival_time" : {
                               "text" : "2:28pm",
                               "time_zone" : "Europe/Paris",
                               "value" : 1380457730
                            },
                            "departure_stop" : {
                               "location" : {
                                  "lat" : 48.860817,
                                  "lng" : 2.325676
                               },
                               "name" : "Musée d'Orsay"
                            },
                            "departure_time" : {
                               "text" : "2:21pm",
                               "time_zone" : "Europe/Paris",
                               "value" : 1380457288
                            },
                            "headsign" : "Versailles - Château / Saint-Quentin / Chaville - Vélizy / Pontoise",
                            "headway" : 478,
                            "line" : {
                               "agencies" : [
                                  {
                                     "name" : "RATP - SNCF"
                                  }
                               ],
                               "color" : "#f2c71c",
                               "short_name" : "RER C",
                               "text_color" : "#000000",
                               "vehicle" : {
                                  "icon" : "//maps.gstatic.com/mapfiles/transit/iw/6/rail.png",
                                  "local_icon" : "//maps.gstatic.com/mapfiles/transit/iw/6/fr-paris-rail.png",
                                  "name" : "Train",
                                  "type" : "HEAVY_RAIL"
                               }
                            },
                            "num_stops" : 3
                         },
                         "travel_mode" : "TRANSIT"
                      },
                      {
                         "distance" : {
                            "text" : "0.7 km",
                            "value" : 673
                         },
                         "duration" : {
                            "text" : "9 mins",
                            "value" : 519
                         },
                         "end_location" : {
                            "lat" : 48.858329,
                            "lng" : 2.2946919
                         },
                         "html_instructions" : "Walk to Avenue Anatole France, 75007 Paris, France",
                         "polyline" : {
                            "points" : "y~diHeb~LcMuJQVACO_@K]cAiBaAcBo@cAqAwBLWm@cAbCmE"
                         },
                         "start_location" : {
                            "lat" : 48.855014,
                            "lng" : 2.289154
                         },
                         "steps" : [
                            {
                               "distance" : {
                                  "text" : "0.3 km",
                                  "value" : 285
                               },
                               "duration" : {
                                  "text" : "4 mins",
                                  "value" : 225
                               },
                               "end_location" : {
                                  "lat" : 48.857269,
                                  "lng" : 2.291018
                               },
                               "polyline" : {
                                  "points" : "y~diHeb~LcMuJ"
                               },
                               "start_location" : {
                                  "lat" : 48.855014,
                                  "lng" : 2.289154
                               },
                               "travel_mode" : "WALKING"
                            },
                            {
                               "distance" : {
                                  "text" : "0.2 km",
                                  "value" : 235
                               },
                               "duration" : {
                                  "text" : "3 mins",
                                  "value" : 186
                               },
                               "end_location" : {
                                  "lat" : 48.8588284,
                                  "lng" : 2.2932032
                               },
                               "html_instructions" : "Head \u003cb\u003enortheast\u003c/b\u003e on \u003cb\u003eQuai Branly\u003c/b\u003e toward \u003cb\u003ePromenade d'Australie\u003c/b\u003e",
                               "polyline" : {
                                  "points" : "}leiH{m~LQVACO_@K]cAiBaAcBo@cAqAwB"
                               },
                               "start_location" : {
                                  "lat" : 48.857269,
                                  "lng" : 2.291018
                               },
                               "travel_mode" : "WALKING"
                            },
                            {
                               "distance" : {
                                  "text" : "11 m",
                                  "value" : 11
                               },
                               "duration" : {
                                  "text" : "1 min",
                                  "value" : 12
                               },
                               "end_location" : {
                                  "lat" : 48.8587578,
                                  "lng" : 2.2933179
                               },
                               "html_instructions" : "Turn \u003cb\u003eright\u003c/b\u003e",
                               "maneuver" : "turn-right",
                               "polyline" : {
                                  "points" : "uveiHo{~LLW"
                               },
                               "start_location" : {
                                  "lat" : 48.8588284,
                                  "lng" : 2.2932032
                               },
                               "travel_mode" : "WALKING"
                            },
                            {
                               "distance" : {
                                  "text" : "36 m",
                                  "value" : 36
                               },
                               "duration" : {
                                  "text" : "1 min",
                                  "value" : 27
                               },
                               "end_location" : {
                                  "lat" : 48.858994,
                                  "lng" : 2.2936589
                               },
                               "html_instructions" : "Turn \u003cb\u003eleft\u003c/b\u003e",
                               "maneuver" : "turn-left",
                               "polyline" : {
                                  "points" : "gveiHg|~Lm@cA"
                               },
                               "start_location" : {
                                  "lat" : 48.8587578,
                                  "lng" : 2.2933179
                               },
                               "travel_mode" : "WALKING"
                            },
                            {
                               "distance" : {
                                  "text" : "0.1 km",
                                  "value" : 106
                               },
                               "duration" : {
                                  "text" : "1 min",
                                  "value" : 69
                               },
                               "end_location" : {
                                  "lat" : 48.858329,
                                  "lng" : 2.2946919
                               },
                               "html_instructions" : "Turn \u003cb\u003eright\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003eDestination will be on the right\u003c/div\u003e",
                               "maneuver" : "turn-right",
                               "polyline" : {
                                  "points" : "uweiHk~~LbCmE"
                               },
                               "start_location" : {
                                  "lat" : 48.858994,
                                  "lng" : 2.2936589
                               },
                               "travel_mode" : "WALKING"
                            }
                         ],
                         "travel_mode" : "WALKING"
                      }
                   ],
                   "via_waypoint" : []
                }
             ],
             "overview_polyline" : {
                "points" : "mdfiHykgMh@P|At@B@}AzJGDCXShApCvANJFDGb@oB`OH^F^FNVRBH^VxBxARt@ERo@xC]p@mAdDUr@i@nCS~@PJU|@VNgJpc@}@hGU|BIvBRff@@tKPrZRxTXlG~BtLpDlJlJnOtHrL|CzCnBp@zCrAxAz@FWcMuJQVQc@K]cAiBqBgDqAwBLWm@cAbCmE"
             },
             "summary" : "",
             "warnings" : [
                "Walking directions are in beta.    Use caution – This route may be missing sidewalks or pedestrian paths."
             ],
             "waypoint_order" : []
          }
       ],
       "status" : "OK"
    }
    

    Reference: The Google Directions API: RequestParameters