Я пытаюсь заменить значок маркера Google Map Полем Это ошибка или их способ решить эту проблему? < /P>
Код: Выделить всё
Map Route with Custom Markers
#map {
height: 400px;
width: 100%;
}
$(document).ready(function() {
var map;
var directionsService;
var directionsRenderer;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 40.7128, lng: -74.0060}, // New York
zoom: 10
});
directionsService = new google.maps.DirectionsService();
directionsRenderer = new google.maps.DirectionsRenderer({
map: map
});
}
function calculateAndDisplayRoute(start, end, waypoints) {
directionsService.route({
origin: start,
destination: end,
waypoints: waypoints,
optimizeWaypoints: true,
travelMode: 'DRIVING'
}, function(response, status) {
if (status === 'OK') {
directionsRenderer.setDirections(response);
var route = response.routes[0];
for (var i = 0; i < route.legs.length; i++) {
addCustomMarkers(route.legs[i].start_location, 'Start');
addCustomMarkers(route.legs[i].end_location, 'End');
}
if (waypoints) {
waypoints.forEach(function(waypoint) {
addCustomMarkers(waypoint.location, 'Waypoint');
});
}
} else {
window.alert('Directions request failed due to ' + status);
}
});
}
function addCustomMarkers(location, label) {
new google.maps.Marker({
position: location,
map: map,
label: label,
icon: { // Custom marker icon
url: "https://i.postimg.cc/hvp0CVp9/detox-logo-1.png", // Replace with your icon URL
scaledSize: new google.maps.Size(30, 30),
labelOrigin: new google.maps.Point(15, -10)
}
});
}
initMap();
// Example usage:
var start = 'New York, NY';
var end = 'Philadelphia, PA';
var waypoints = [
{
location: "Trenton, NJ",
stopover: true
}
];
calculateAndDisplayRoute(start, end, waypoints);
});
Подробнее здесь: https://stackoverflow.com/questions/794 ... ith-my-own