Overriding large popup to google maps directions

I happily implemented v2 google maps on my site without a hitch, I am also successfully following directions using GDirections.load ().

I need to do this to stop the mini-map popup when you select a specific step in the routing directions. So when the user clicks Step 3, instead of the default popup showing the minimap, I would like to add a custom icon at that position.

Hope this makes sense Thanks in advance guys.

+2


a source to share


1 answer


You need to add a handler to the GDirections object for the addoverlay event:

GEvent.addListener(gdir, "addoverlay", onGDirectionsAddOverlay);

      



When the onGDirectionsAddOverlay handler is called, you can iterate over the new markers and replace them with copies that open a custom info window:

for (var i = 0; i <= gdir.getNumRoutes(); i++) 
{
    var originalMarker = gdir.getMarker(i);
    latLngs[i] = originalMarker.getLatLng();
    icons[i] = originalMarker.getIcon();
    newMarkers[i] = new GMarker(latLngs[i], { icon: icons[i], draggable: true, title: 'Kan flyttes' });
    map.addOverlay(newMarkers[i]);

    // add stuff to your newMarkers[i] click event...
    // ..

    // Now we can remove the original marker safely
    map.removeOverlay(originalMarker);
}

      

+2


a source







All Articles