Android

Invalid request. Missing the ‘origin’ parameter. Google Map directions request URL error

Google Map Direction request API changed

It seems Google Map Direction request API changed, which is used to get polyline points to draw drive path.

Previously, I implemented drawing driving path on Map using below directions request. And this link worked perfectly, I used to get all the waypoints information, with it.

https://maps.googleapis.com/maps/api/directions/json?
waypoints=optimize:true|52.28582710000001,-1.1141665|52.2777244,-1.1581097&
sensor=false

but currently, I see this URL is not working any more, and its showing this message when i access above URL in web browser

{
"error_message": "Invalid request. Missing the 'origin' parameter.",
"routes": [
],
"status": "REQUEST_DENIED"
}

After searching for a while i found this link, and I see this info

origin (required) specifies the start location from which to calculate directions. This value may either be specified as a String (e.g. "Chicago, IL") or as a LatLng value.
destination (required) specifies the end location to which to calculate directions. This value may either be specified as a String (e.g. "Chicago, IL") or as a LatLng value.
travelMode (required) specifies what mode of transport to use when calculating directions. Valid values are specified in Travel Modes below.

It seems like Google directions API expecting these parameters origin, destination and travelMode in the directions request URL. and i see, TravelMode Driving is default

google.maps.TravelMode.DRIVING (Default) indicates 
standard driving directions using the road network.

So, I implemented code to produce this URL

https://maps.googleapis.com/maps/api/directions/json?
origin=52.28582710000001,-1.1141665&destination=52.2777244,-1.1581097&
waypoints=optimize:true|52.28582710000001,-1.1141665|52.2777244,-1.1581097&
sensor=false

and it worked fine and got the polyline points information.

Hope it helps somebody.

Ref links
Draw path on Map: http://javapapers.com/android/draw-path-on-google-maps-android-api/
Directions Url: https://developers.google.com/maps/documentation/javascript/directions

One thought on “Invalid request. Missing the ‘origin’ parameter. Google Map directions request URL error

Leave a Reply

Your email address will not be published. Required fields are marked *