Google maps API: Marker image positioning

点点圈 提交于 2019-12-05 01:27:49

Try this on for size.

var markerImage = new google.maps.MarkerImage('/img/icon/here.png',
    new google.maps.Size(80, 80), //size
    new google.maps.Point(0, 0), //origin point
    new google.maps.Point(0, 80)); // offset point
marker[stamp] = new google.maps.Marker({
    position: loc, // loc is a variable with my lngLat object
    title: params.name,
    map: window.gMaps[params.map],
    icon: markerImage
});

You want the 'anchor' property of MarkerImage. Note that the origin property comes before anchor in the constructor call. If you're not using sprites, you can just send null for the optional parameters.

If your marker is 80x60 and you want the anchor in the middle of the left side, create it like this:

var markerImage = new google.maps.MarkerImage('customIcon.png', new google.maps.Size(80, 60), null, new google.maps.Point(0, 30));

See also Google's example.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!