Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide marker from directions service in google maps api v3

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);
        }
    });
}
like image 959
Josh Mouse Avatar asked Jul 16 '12 18:07

Josh Mouse


People also ask

How do you remove marker from Maps?

Click the marker to reveal the editing options. Click the "Delete" link in the lower-left corner of the dialog box.

How do I change the color of a marker in Google Maps API?

Add different color markerspng at the end of the URL to get a blue marker. To add a green marker simply change it to green-dot. png so that the URL will be http://maps.google.com/mapfiles/ms/icons/green-dot.png .


1 Answers

When instatiating the DirectionsRenderer, set suppressMarkers to true.

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

Here's the reference

like image 101
Heitor Chang Avatar answered Sep 23 '22 19:09

Heitor Chang