Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample waypoint to use in the directions service #37

Closed
Kodextor opened this issue Jan 2, 2014 · 9 comments
Closed

Sample waypoint to use in the directions service #37

Kodextor opened this issue Jan 2, 2014 · 9 comments

Comments

@Kodextor
Copy link
Contributor

Kodextor commented Jan 2, 2014

I have been trying to use directions service with waypoints, but wasn't able to. Could someone please help me out with a sample waypoints array using location coordinates to pass to the directions().

@moshen
Copy link
Owner

moshen commented Jan 4, 2014

Have you tried something like the example query in the docs here:
https://developers.google.com/maps/documentation/directions/?csw=1#Waypoints
?

You can pass either pipe separated textual destinations or lat,lng.

@Kodextor
Copy link
Contributor Author

Kodextor commented Jan 9, 2014

I tried calling the url directly... I will try to check this later and will let you know... Thanks though..

@leandroz
Copy link

Hi!, i am trying to use the directions services with waypoints. The origin and destination are the same address and then i have two more address in an array with location like this:
var WayPoints = [{location: recogida },{location: destino}];
Where recogida and destino are both adresses.
When i call the function and i passed the waypoints array as 6th argument, appears like the directions service is not using the waypoints, because i receive a response without waypoint_order and the overview_polyline is only the origin and destination point (are the same). Is working ok?

@fabriziomoscon
Copy link
Collaborator

@leandroz the direction function has changed:
https://github.com/moshen/node-googlemaps/blob/master/lib/googlemaps.js#L148

if you can provide a test for your case we can look into the issue

@leandroz
Copy link

The problem is with the function buildUrl, stringify and how you have to pass the arguments waypoints to Google Maps.
Here is the url example from Google Maps documentation:
http://maps.googleapis.com/maps/api/directions/json?origin=Boston,MA&destination=Concord,MA&waypoints=Charlestown,MA|Lexington,MA&sensor=false

See that each waypoints is separated by |, but stringify escaped an array like:

querystring.stringify({ foo: 'bar', baz: ['qux', 'quux'], corge: '' })
// returns
'foo=bar&baz=qux&baz=quux&corge='

If you prove the test with waypoints it will fail.
Thats the problem.

@fabriziomoscon
Copy link
Collaborator

I think this is the same issue as #49

I can see a possible confusion arising when people think waypoints is an array, whereas passing a string will make it work.

Have I understood the problem correctly @leandroz ?

@leandroz
Copy link

Hi @fabriziomoscon !
I am passing the waypoints like this

[{location: LatLngOrigin}, {location: LatLngDestination }]

What is the proper way to do it?

@leandroz
Copy link

LatLngOrigin + "|" + LatLngDestination

Is the right way?

@fabriziomoscon
Copy link
Collaborator

Google expects waypoints as a string of pipe separated locations. An the library doesn't have any conversion for the input you pass.

Please pass something similar to:

var waypoints = "Charlestown,MA|Lexington,MA";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants