Like many I am trying to migrate to AdvancedMarkerElement in Google Maps Javascript API.
I have followed the documentation and so far have:
<script defer src="https://maps.googleapis.com/maps/api/js?key={{env("GOOGLE_JAVASCRIPT_APIKEY")}}&loading=async&callback=gmapinit&v=weekly&libraries=marker"></script>
then further for the callback:
async function gmapinit() {//used as callback,required by the api when loading it
const {AdvancedMarkerElement} = await google.maps.importLibrary("marker");
const {PinElement} = await google.maps.importLibrary("marker");
GMap = new G_Map();//own wrapper class
}
Successfully working is a basic AdvancedMapMarker on the map with:
let marker = new google.maps.marker.AdvancedMarkerElement({
map: this.map, position: markerposition, title: title,
});
let iconImg = document.createElement("img");
iconImg.src = optargs.icon;
marker.content = iconImg;
However there is no scaling for the image here, which I would like to do programmatically.
So attempting to change the above to
let iconImg = document.createElement("img");
iconImg.src = optargs.icon;
let pin = new PinElement({
scale: 1.5,
content: iconImg,
});
let marker = new google.maps.marker.AdvancedMarkerElement({
map: this.map, position: markerposition, title: title,
content: pin.element
});
Is where the error occurs with:
ReferenceError: PinElement is not defined
So my question is how do I load PinElement to code as per the examples – I am obviously missing something simple somewhere