How to specify anchor in AdvancedMarkerElement?

  Kiến thức lập trình

Since support for google.maps.Marker ends on February 21, 2024, we are considering migrating to google.maps.marker.AdvancedMarkerElement.
I replace the marker icon with an image, but I don’t know how to specify the anchor.
In the Google sample below, the anchor of beachflag.png seems to be at the bottom left (0, 32), but the anchor is displayed at the bottom center.
Create markers with graphics

With google.maps.Marker, I can specify the anchor as shown below, but how do you specify the anchor with AdvancedMarkerElement?

let icon = {
   url: "https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png",
   size: new google.maps.Size(20, 32),
   origin: new google.maps.Point(0, 0),
   anchor: new google.maps.Point(0, 32), //bottom left
 };
 
let marker = new google.maps.Marker({
     position: position,
     map: map,
     icon: icon
 });

New contributor

函館太郎 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT