谷歌地图v3标记鼠标悬停工具提示 [英] google maps v3 marker mouseover tooltip

查看:111
本文介绍了谷歌地图v3标记鼠标悬停工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在鼠标悬停在标记上时使用div创建工具提示,但我不知道如何获取屏幕位置以将div放在正确的位置,以下是我的代码:

I want to put a tooltip made myself with divs when the mouse is over a marker, but I don't know how to get the screen position to put the div on the correct position, here is my code:

google.maps.event.addListener(marker, "mouseover", function() {
            divover.css("left", marker.get("left"));
            divover.css("top", marker.get("top"));
            divover.css("display", "block");
});

google.maps.event.addListener(marker, "mouseout", function() {
            divover.css("display", "none");
});

显然get方法失败。任何想法?

Obviously the get method fails. Any Idea?

推荐答案

这是一个棘手的问题。在API的第2版中,您可以执行以下操作:

This is a tricky one. In v2 of the API, you can do:

map.fromLatLngToContainerPixel(marker.getLatLng(), zoomLevel);

在v3中,来自LaLengToContainerPixel的方法已被移至MapCanvasProjection对象。要获得MapCanvasProjection对象,您需要在OverlayView对象上调用getProjection。它看起来像Marker类是从OverlayView扩展的,但不幸的是它没有getProjection方法。我不知道为什么 - 可能值得提交bug。

In v3, the method fromLatLngToContainerPixel has been moved to the MapCanvasProjection object. To get a MapCanvasProjection object, you need to call getProjection on an OverlayView object. It looks like the Marker class is extended from OverlayView, but unfortunately it doesn't have the getProjection method. I have no idea why - may be worth filing a bug.

我这样做的方式是通过基于OverlayView创建自己的自定义标记类,所以它仍然有getProjection方法:

The way I've done it is by creating my own custom marker class, based on OverlayView, so it still has the getProjection method:

var point = this.getProjection().fromLatLngToDivPixel(this.latlng_);

您可以在自定义叠加层或复制其 example ,以帮助您入门。

You can read Google's tutorial on custom overlays or copy their example to get you started.

这篇关于谷歌地图v3标记鼠标悬停工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆