I am using the Google Maps API, and trying to add markers on the map along a route. These markers have a title and label as well. Everything is working as intended, the markers are being displayed correctly, including the title, butt he labels are not showing. I checked and the labels are being passed correctly to the method to make the markers, they just wont show up for some reason.
Here is the code for making the markers
function markerMaker(lat, lng, map, markerTitle, label) {
const latLng = { lat: lat, lng: lng };
const marker = new google.maps.Marker({
position: latLng,
map,
title: markerTitle,
label: label,
optimized: false,
});
console.log("passed label", label);
const infoWindow = new google.maps.InfoWindow({
content: markerTitle,
ariaLabel: markerTitle,
});
marker.addListener("click", function () {
infoWindow.open({
anchor: marker,
map,
});
});
return marker;
}
and this is the function it is being passed to when calculating the route
const res = await directionsService
.route({
origin: startingPoint,
destination: endingPoint,
waypoints: brewDirectionArray,
optimizeWaypoints: true,
travelMode: "DRIVING",
})
.catch((err) => {
console.error("error", err);
});
directionsRenderer.setDirections(res);
const routeCords = res.routes[0].legs;
const waypointOrder = res.routes[0].waypoint_order;
const labelLetters = "BCDEFGHIJKLMNOPQRSTUVWXYZ";
let markers = [];
for (let i = 0; i < routeCords.length; i++) {
if (i === 0) {
let markerLabel = startingPoint === endingPoint ? "" : "A";
const startLat = routeCords[i].start_location.lat();
const startLng = routeCords[i].start_location.lng();
const marker = markerMaker(
startLat,
startLng,
map,
startingPoint,
markerLabel
);
markers.push(marker);
}
let markerTitle;
let markerLabel = labelLetters[i];
if (i === routeCords.length - 1) {
markerTitle = endingPoint;
if (startingPoint === endingPoint) {
markerLabel = `A/${labelLetters[i]}`;
}
} else {
markerTitle = breweryAddressAndNameArr[waypointOrder[i]];
}
const lat = routeCords[i].end_location.lat();
const lng = routeCords[i].end_location.lng();
const marker = markerMaker(lat, lng, map, markerTitle, "B");
markers.push(marker);
}
return res;
}
I should add that this seemingly happened overnight. before this, I had labels being displayed no problem.
I have tried passing individual letters as the argument for the labels , and messing around with the CSS, as well as adding classes to the markers, but no cigar.
Any Suggestions?