How to get travel duration and fare estimation?

199 views
Skip to first unread message

Anton Rifco

unread,
Feb 4, 2013, 12:39:56 PM2/4/13
to gothe...@googlegroups.com
Hi folks,

I've been migrating from google maps to gothere, due to the need for fare estimation on our site. and gothere provides it.
I tested the code provide in http://gothere.sg/api/maps/reference.html#GDirections to get travel duration. but seems there's an error, like the following:

if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(1.362083, 103.819836), 11);
map.addControl(new GSmallMapControl());
map.addControl(new GScaleControl());
       
directions = new GDirections(map, document.getElementById("panel"));
directions.load("from: 018956 to: 049835", {travelMode: G_TRAVEL_MODE_TRANSIT});
console.log(directions.getDuration());
       
}

I got the following error:
Uncaught TypeError: Cannot read property 'Duration' of undefined

Please advice

Regards,
Anton

Adrian Vu

unread,
Mar 12, 2013, 7:24:20 AM3/12/13
to gothe...@googlegroups.com
Hi,

I was working on it as well and I have a solution for it. You need to create an event listener to detect that the load is complete before accessing the variable.

Here's an example:
 
directions = new GDirections(map, document.getElementById("panel"));
directions.load("from: 018956 to: 049835", {travelMode: G_TRAVEL_MODE_TRANSIT});
GEvent.addListener(directions, "load", function() {
  console.log(directions.getDuration());
}

hope that helps..
Reply all
Reply to author
Forward
0 new messages