How do I change the Start and End marker image in Google Maps v3 API for Directions

后端 未结 3 1751
渐次进展
渐次进展 2021-02-19 11:26

I have a route plotted fine on using DirectionsRender but I cannot find out how to replace the generic Google markers with my own.

I know and use this in a normal Google

3条回答
  •  無奈伤痛
    2021-02-19 11:49

    this is how you need to approach it

    Declare all your image icons as shown below

    var movingIcon = new google.maps.MarkerImage('/img/icon_moving.jpg');
    var startIcon = new google.maps.MarkerImage('/img/icon_start.png');
    

    Then while creating the marker, use the icon option to set the specific image to that marker

    marker = new google.maps.Marker({
                position: point,
                map: map,
                icon: movingIcon
                });
    

提交回复
热议问题