Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
131
rated 0 times [  133] [ 2]  / answers: 1 / hits: 15964  / 15 Years ago, thu, june 18, 2009, 12:00:00

Does this look like it should work? I'm wanting to generate directions from one latitude/longitude to another latitude/longitude.



var dirMap = new GMap2($(#dirMap).get(0));
var wp = new Array(2);
wp[0] = new GLatLng(35.742149,139.337218);
wp[1] = new GLatLng(35.735347,139.328485);

var marker = new GMarker(wp[1]);
dirMap.addOverlay(marker);
dirMap.setCenter(wp[0], 12);
dirMap.setUIToDefault();

// load directions
directions = new GDirections(dirMap);
directions.load(from: [email protected],100.337218 to: [email protected],100.3267);


The map loads fine, but the directions don't come in. I've tried it this way too:



var dirMap = new GMap2($(#dirMap).get(0));
var wp = new Array(2);
wp[0] = new GLatLng(32.742149,119.337218);
wp[1] = new GLatLng(32.735347,119.328485);

var marker = new GMarker(wp[1]);
dirMap.addOverlay(marker);
dirMap.setCenter(wp[0], 12);
dirMap.setUIToDefault();

// load directions
directions = new GDirections(dirMap);
directions.loadFromWaypoints(wp);


Same thing... map but no directions. Any help is greatly appreciated, thank you in advance!


More From » api

 Answers
116

I can't see anything obvious at first glance at your code, so my first guess is a failure coming back in for the GDirections request (I am also assuming you have checked the javascript error log for any errors, Tools/Error Console if you haven't already done this).



I suggest you add an error handler for your GDirections object, this will give you some indication what is happening with your request:



GEvent.addListener(directions, error, handleErrors);


and in the handleErrors callback have a look in:



directions.getStatus().code


Compare with the Geo Status Codes.



EDIT: Ok, I just tried out your code here and it works perfectly. I can only assume that there is some other problem on your page that is causing the issue. Can you post a link in the question so we can check it out ?


[#99287] Monday, June 15, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aidanl

Total Points: 156
Total Questions: 102
Total Answers: 112

Location: Saint Lucia
Member since Wed, Feb 8, 2023
1 Year ago
aidanl questions
Thu, Feb 10, 22, 00:00, 2 Years ago
Thu, Dec 17, 20, 00:00, 4 Years ago
Fri, Jul 24, 20, 00:00, 4 Years ago
Thu, Jul 16, 20, 00:00, 4 Years ago
Mon, Apr 6, 20, 00:00, 4 Years ago
;