Google Maps API: GDirections with no Markers
February 14th, 2008
I’ve been working with the Google Maps API quite a lot over the past couple of weeks, but one thing that has continuously thwarted me, has been how to remove the little Info Window maps from a route that has been loaded using GDirections and finally I have found the answer. When you load a GDirections object with the optional map panel in the constructor it automatically places the route and markers on the map. The work around is to not provide any arguments to the constructor, and instead load retrieve the GPolyline with the getPolyline method and the getPolyline: true option. Then in the “load” event, add it to the map and presto.
var dirs = new GDirections();
GEvent.addListener(dirs, "load", function() {
var polyline = dirs.getPolyline();
map.addOverlay(polyline);
});
dirs.loadFromWaypoints("Directions from here to there", {getPolyline: true});
brucini said:
great solution. i’ve been having the same problem. however, i had always managed to fix it with the following actions: control + f5 . presto.
Michael said:
Hey Good answer. An annotated code fragment or a link would be useful as your long paragraph is hard to decipher
Adriano said:
Exempls???? cods font??????
friism said:
Something like this:
—
var gDir;
var map;
function load() {
if (google.maps.BrowserIsCompatible()) {
gDir = new GDirections();
gDir.loadFromWaypoints(mywaypoints, {getPolyline: true});
GEvent.addListener(gDir, “load”, onGDirectionsLoad);
//also init map
}
}
function onGDirectionsLoad(){
map.addOverlay(gDir.getPolyline());
}
—
Jonny said:
How do you also add the directions? (as well as the polyline)
I want to use your method because I don’t want any markers to be displayed.
Thanks.
Tim said:
Thanks for this Michael, saved me loads of time.
Jonny,
Try this
var gDir=new GDirections(null, document.getElementById(“directions”));
passing null still means no Markers, but passing the id of your directions container element
will populate teh directions text in there. Hope that helps someone else do what I needed to do.
Brijesh said:
Awesome solution I have been trying to get rid of the Marker but could not & was finding alternative soluntion & this works excellent
Pablo said:
Thanks a lot for the tip, works great
Tran Tai said:
var gDir=new GDirections(null)
Thank, this help me !