Google 地图 v3 自定义标记图标无法保持其在地图上的位置
使用 Google 地图 v3 进行开发。
由于某种原因,我的自定义标记图标“更改”了它在放大时的位置。看起来它有某种“填充”属性,不会随着缩放而改变。
这意味着它在最大缩放(18)上的位置是正确的,但是如果我更改缩放值,它会“移动”一点到顶部,并且在较小的缩放值上会出现问题,因为它看起来与这是。
标记定义为:
var image = new google.maps.MarkerImage('img/antennas/img.png',new google.maps.Size(100, 100));
这可能会有所帮助:标记图标是方形的,100x100px,它的中心位于图像的中间,而不是像“正常”标记那样位于底部。
更新:我是否必须对锚点属性执行某些操作?
Developing with Google Maps v3.
For some sort of reason, my custom marker icon "change" it's position on zoom in-out. It looks like it have some sort of "padding" property, that not changes together with zoom.
It means that it position is correct on maximum zoom (18), but if I change zoom value, it "moves" a bit to top, and it makes problem on smaller zoom values, because it looks like it is not on same position as it is.
Marker is defined as:
var image = new google.maps.MarkerImage('img/antennas/img.png',new google.maps.Size(100, 100));
This maybe can help: marker icon is squared shape, 100x100px, and it's center is in middle of the image, not on the bottom like "normal" markers.
UPDATE: do I have to do something with anchor property?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您必须设置标记的锚点。默认为中心底部。
请参阅 http://code.google.com/apis/maps/文档/javascript/reference.html#MarkerImage
You have to set the anchor of the marker. The default is center bottom.
See http://code.google.com/apis/maps/documentation/javascript/reference.html#MarkerImage
除了使用 Marker 之外,还可以使用 MarkerImage 作为标记。
在此示例中,我使用的标记是一个中间有一个点的圆,因此我始终希望它居中。
例子
Instead of using only a Marker, use also a MarkerImage, to be used as the marker.
In this example I use a mark that is a circle with a point in the middle, so I always want it centered.
Example
根据您对“填充”的描述,这听起来像是您的 MarkerImage 的定位问题。尝试调整 MarkerImage 的锚点属性。默认情况下,锚点位于图像的底部中心。如果您希望图像居中,则必须将锚点向下移动图像大小的一半以使其居中。
请参阅 http://code.google.com/ intl/no/apis/maps/documentation/javascript/reference.html#MarkerImage 供参考。
Based on your description of "padding", this sounds like it is an issue with the positioning of your MarkerImage. Try tweaking the anchor property of the MarkerImage. By default, the anchor is at the bottom center of your image. If you want the image to be centered, you will have to move the anchor down half the size of the image to center it.
See http://code.google.com/intl/no/apis/maps/documentation/javascript/reference.html#MarkerImage for reference.
查看图标中的anchor属性:anchor: new google.maps.Point(0, 0)
See the anchor property in icon: anchor: new google.maps.Point(0, 0)