Using Google Maps API to get travel time data -


All the examples using the Google Map API seem to show some kind of map. I would like to include data about the time of the train journey by you, when you ask the ABC for the road details on the site. And only this data is possible without loading the map for the last visitor?

Yes, it's definitely possible the API. You can create a GDirections object without a map or directions DIV. You can request A to B load and then call the method to get total travel time.

First you need to create an object:

  // No map or result is required to be removed because we are only interested in travel time. Var Directions = New GDirection ();  

Then request your load to resolve the directions (I have used two latitude and underlines as my starting and end points, but you can also use the address here ):

  var wp = new array (); Wp [0] = new GLTLNG (32.742149,11 9.337218); Wp [1] = new GLTLNG (32.735347,11 9.328485); Directions.loadFromWaypoints (WP);  

Then you need to listen for the load event so that after the instructions are resolved, you can call getDuration :

  GEvent.addListener (command, "load", function () {$ ('log'). InnerHTML = directions.getDuration (.seconds + "seconds";});  

You and others can check for options that you can give to GDiurection objects (such as walking distance etc ...) for you geographic failures The error should also listen to the event.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -