我使用图标标记来代替谷歌地图的默认标记,但我使用图标标记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]
您不能仅通过url
选项使用svg
。这必须是内联的,或者你为它创建自己的字形,参见图形标记。
另一种选择是使用png
图形代替svg
。