简体   繁体   English

如何获取相对于HTML页面的标记位置

[英]How to obtain marker position relative to HTML page

I am using Google Maps API V3 for JavaScript, I do like to get a Marker's position relatively to my page in pixels (left, top), so I can add a custom label when hoving the mouse over my marker. 我正在使用谷歌地图API V3 for JavaScript,我喜欢相对于我的页面像素(左,上)获得标记的位置,所以我可以在鼠标悬停在我的标记上时添加自定义标签。 How do I get that position? 我如何获得这个职位?

If your referring to getting the position of your mouse while you hover, use overlay in the listener to get the projection and the pixel coordinates. 如果您在悬停时指的是获取鼠标的位置,请在侦听器中使用叠加来获取投影和像素坐标。 Overlays are objects on the map that are tied to latitude/longitude coordinates, so they move when you drag or zoom the map. 叠加层是地图上与纬度/经度坐标相关联的对象,因此当您拖动或缩放地图时它们会移动。 If you want to place an image on a map, you can use a GroundOverlay object or you can create your own Custom Overlays with the use of OverlayView class. 如果要在地图上放置图像,可以使用GroundOverlay对象,也可以使用OverlayView类创建自己的自定义叠加

Sample code using OverlayView: 使用OverlayView的示例代码:

var overlay = new google.maps.OverlayView();
overlay.draw = function() {};
overlay.setMap(map); // 'map' is new google.maps.Map(...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM