Google Maps v3自定义标记图标无法保持其在地图上的位置

use*_*003 8 google-maps google-maps-api-3 google-maps-markers

使用Google Maps v3进行开发.

出于某种原因,我的自定义标记图标"更改"它在放大输出时的位置.看起来它有某种"填充"属性,不会随着缩放而变化.

这意味着它在最大缩放时的位置是正确的(18),但是如果我改变缩放值,它会"移动"一点到顶部,并且它会在较小的缩放值上产生问题,因为它看起来像是在不同的位置上它是.

标记定义为:

var image = new google.maps.MarkerImage('img/antennas/img.png',new google.maps.Size(100, 100));
Run Code Online (Sandbox Code Playgroud)

这可能有所帮助:标记图标是方形,100x100px,它的中心位于图像的中间,而不是像"普通"标记一样位于底部.

更新:我必须对锚属性做些什么吗?

puc*_*ead 6

您必须设置标记的锚点.默认为中心底部.

请参阅http://code.google.com/apis/maps/documentation/javascript/reference.html#MarkerImage


dwb*_*ito 5

除了使用 Marker,还使用 ​​MarkerImage 作为标记。

在这个例子中,我使用了一个中间有一个点的圆的标记,所以我总是希望它居中。

例子

 var marker_image = new google.maps.MarkerImage(
        '../Media/icon_maps_marker.png',
         null,
         // The origin for my image is 0,0.
         new google.maps.Point(0, 0),
         // The center of the image is 50,50 (my image is a circle with 100,100)
         new google.maps.Point(50, 50)
     );
    var marker = new google.maps.Marker({
        clickable: true,
        map: map,
        position: center_location,
        icon: marker_image,
    });
Run Code Online (Sandbox Code Playgroud)