Get Position of Mouse Cursor on Mouseover of Google Maps V3 API Marker

后端 未结 6 656
名媛妹妹
名媛妹妹 2020-12-01 16:39

I am trying to make a div visible at the position of the cursor when the cursor mouseover a marker using jQuery. Its kind of like a tooltip. However I cannot se

6条回答
  •  执笔经年
    2020-12-01 17:15

    Here's a solution that uses the MouseEvent of the click event but does not rely on accessing that via an undocumented property that can change at any time like 'ub' or 'wb' (I think it's 'ya' currently).

    map.data.addListener('mouseover', function (e) {
        var keys = Object.keys(e);
        var x, y;
        for (var i = 0; i < keys.length; i++) {
            if (MouseEvent.prototype.isPrototypeOf(e[keys[i]])) {
                x = e[keys[i]].clientX;
                y = e[keys[i]].clientY;
            }
        }
    });
    

提交回复
热议问题