13
votes

I'm using this service https://developers.google.com/maps/documentation/javascript/directions to create a route between two markers.

The problem is that when I run the function to create the path, he enters me two markers by default from google maps (the beginning and end) when I had created the markers with different style.

Result: at each point have my marker and the marker's default google maps above.

How can I hide the marker created by google?

The code I'm using is:

function makePathToMarker(position1, position2) {
    var request = {
        origin: new google.maps.LatLng(myLocation.split(",")[0],myLocation.split(",")[1]),
        destination: new google.maps.LatLng(position1, position2),
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };

    var directionsService = new google.maps.DirectionsService();

    directionsService.route(request, function(response, status) {
        if (status == google.maps.DirectionsStatus.OK) {
            directionsDisplay.setDirections(response);
        }
    });
}
2

2 Answers

45
votes

When instatiating the DirectionsRenderer, set suppressMarkers to true.

  directionsDisplay = new google.maps.DirectionsRenderer(
  {
      suppressMarkers: true
  });

Here's the reference

1
votes

Depends of what you need

directionsDisplay.setOptions({ 
     suppressPolylines: true, 
     suppressMarkers: true
});