Google Maps API: GDirections with no Markers

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();
dirs.loadFromWaypoints("Directions from here to there", {getPolyline: true});

10 thoughts on “Google Maps API: GDirections with no Markers

  1. great solution. i’ve been having the same problem. however, i had always managed to fix it with the following actions: control + f5 . presto.

  2. Hey Good answer. An annotated code fragment or a link would be useful as your long paragraph is hard to decipher

  3. 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(){

  4. 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.


  5. Thanks for this Michael, saved me loads of time.


    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.

  6. Awesome solution I have been trying to get rid of the Marker but could not & was finding alternative soluntion & this works excellent

  7. Ι’m really inspired along with your writing skills as well as with the structure in your blog. Is this a paid subject or did you modify it your self? Anyway stay up the nice quality writing, it is uncommon to look a great weblog like this one these days..

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>