Been working on moving on to AdvancedMarker since Marker is deprecated in Google Maps.
I’m trying to migrate a marker but they’re rendered it so complicated for nothing…
I used to have a simple svg marker
new google.maps.Marker({
position:loc,
map:map,
title: title,
icon: '/img/marker.svg'
});
Now after migration, I cannot for the life of me figure out how to use the same path for the absolute mess of PinElement.
const pinElement = new google.maps.marker.PinElement({
glyph: new URL('/img/marker.svg'),
});
new google.maps.marker.AdvancedMarkerElement({
position: loc,
map: map,
title: title,
content: pinElement
});
Failed to construct 'URL': Invalid URL
How do I load that URL WITHOUT specifying the domain in the glyph ? We use this in multiple env and so domain can change, that’s the reason I wish to use absolute URL.
2
Answers
I will answer my own question, I might help someone. After going through the documentation that is full of typos and mistakes, I found that solution on a random page :
If you use a
PinElement
, your SVG file will be displayed inside the default balloon marker.If you use your SVG as the
AdvancedMarker
content, the graphic will make the entire marker.