在谷歌地图上替换新图标标记时如何删除默认标记

问题描述 投票:0回答:1

我使用图标标记来替换谷歌地图的默认标记,但我使用图标标记 png,我无法删除默认标记..

这是脚本:

    function myMap() {

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

  <c:forEach var="list" items="${latlongList}" varStatus="status">
  var pointA = new google.maps.LatLng(<c:out value="${list.latCust}"/>,<c:out value="${list.longCust}"/>),
      pointB = new google.maps.LatLng(<c:out value="${list.latDsc}"/>,<c:out value="${list.longDsc}"/>),
  </c:forEach>

  mapProp = {
    zoom: 7,
    center: pointA,
    gestureHandling: 'greedy',
  },
  map = new google.maps.Map(document.getElementById('googleMap'), mapProp),
  // Instantiate a directions service.
  directionsService = new google.maps.DirectionsService,
  directionsDisplay = new google.maps.DirectionsRenderer({
    map: map
  });

  var iconStart = {
            url: '<%=request.getContextPath()%>/resources/images/common/icon-pin-02.svg',
            scaledSize: new google.maps.Size(42, 52), // scaled size
            origin: new google.maps.Point(0,0),
            anchor: new google.maps.Point(16, 32)
  };
  var iconEnd = {
          url: '<%=request.getContextPath()%>/resources/images/common/icon-pin-01.svg',
          scaledSize: new google.maps.Size(39, 49), // scaled size
          origin: new google.maps.Point(0,0),
          anchor: new google.maps.Point(16, 32)
  };

  markerA = new google.maps.Marker({
    position: pointA,
    map: map,
    icon: iconStart
  });

  markerB = new google.maps.Marker({
    position: pointB,
    map: map,
    icon: iconEnd
  });
calculateAndDisplayRoute(directionsService, directionsDisplay, pointA, pointB);
}

function calculateAndDisplayRoute(directionsService, directionsDisplay, pointA, pointB) {
  directionsService.route({
    origin: pointA,
    destination: pointB,
    travelMode: google.maps.TravelMode.DRIVING
  }, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      directionsDisplay.setDirections(response);
      computeTotalDistance(response);
    } else {
      window.alert('Directions request failed due to ' + status);
    }
  });
}

function computeTotalDistance(result) {

var totalDist = 0;
var totalTime = 0;
var myroute = result.routes[0];
var priceFee = 0;

for (i = 0; i < myroute.legs.length; i++) {
    totalDist += myroute.legs[i].distance.value;
    totalTime += myroute.legs[i].duration.value;
}   

}

照片

[![enter image description here][1]][1]

我试图找到一些指南,但似乎无法删除,任何人都可以支持我 如何删除默认标记?非常感谢

[commentttttttttttttttttttttttttttttttttt]

javascript html jquery google-maps google-maps-markers
1个回答
0
投票

您不能只通过

svg
选项使用
url
。这必须是内联的或者您为它创建自己的字形,请参阅graphic-markers

另一种选择是使用

png
grafic 而不是
svg
.

© www.soinside.com 2019 - 2024. All rights reserved.