Javascript firefox中的google map mouseevent显示不正确的坐标

Javascript firefox中的google map mouseevent显示不正确的坐标,javascript,google-maps,firefox,mouseevent,Javascript,Google Maps,Firefox,Mouseevent,我有一个google map api页面,当map div不在浏览器窗口的左上角(0,0)时,它不会从firefox中的鼠标事件返回正确的坐标。如果我在map div中添加任何css填充或边距,google maps中的mouseevent原点仍然从浏览器窗口的左上角开始,而不是map div。mouseevent在IE和Chrome中正常工作,返回正确的lat/lng,但不是Firefox。有人有什么建议要纠正吗 我创建了一个非常简单的示例,它显示了鼠标在地图上移动时的坐标。您可以在地图图像的

我有一个google map api页面,当map div不在浏览器窗口的左上角(0,0)时,它不会从firefox中的鼠标事件返回正确的坐标。如果我在map div中添加任何css填充或边距,google maps中的mouseevent原点仍然从浏览器窗口的左上角开始,而不是map div。mouseevent在IE和Chrome中正常工作,返回正确的lat/lng,但不是Firefox。有人有什么建议要纠正吗

我创建了一个非常简单的示例,它显示了鼠标在地图上移动时的坐标。您可以在地图图像的左上角看到,坐标应为0,0,但Firefox显示为50,50。“信息”窗口显示地图中心的正确lat/lng,当您将鼠标移动到该点时,您可以看到坐标的差异(从左上角移动50个像素)

<html>
<head>
<meta charset="utf-8">
<style>
 body    {font:12px arial; margin:0px}
 #map {
    height:400px;
    width:400px;
}
</style>

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script>
    var map;
    coord = new google.maps.LatLng(38.939201, -94.747640)

    function initialize() {
        var mapOptions = {
            zoom: 16,
            center: coord
        };
        map = new google.maps.Map(document.getElementById('map'), mapOptions);

        google.maps.event.trigger(map, 'resize');

        var coordInfoWindow = new google.maps.InfoWindow();
        coordInfoWindow.setContent('38.939201, -94.747640');
        coordInfoWindow.setPosition(coord);
        coordInfoWindow.open(map);

        google.maps.event.addListener(map, "mousemove", function (event) {
            document.getElementById("footer").innerHTML = "Mouse X Y:" + event.pixel.toString() + " - Lat Lng:" + event.latLng.toString() + "<br />"
                });
     }

    google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map" style="margin-left:50px;margin-top:50px;"></div>
<div id="footer" style="margin-left:50px; padding:10px;"></div>
</body>
</html>

正文{字体:12px arial;边距:0px}
#地图{
高度:400px;
宽度:400px;
}
var映射;
coord=new google.maps.LatLng(38.939201,-94.747640)
函数初始化(){
变量映射选项={
缩放:16,
中心:coord
};
map=new google.maps.map(document.getElementById('map'),mapOptions);
google.maps.event.trigger(映射,'resize');
var coordinfo window=new google.maps.InfoWindow();
coordinfo window.setContent('38.939201,-94.747640');
坐标信息窗口。设置位置(坐标);
坐标信息窗口。打开(地图);
google.maps.event.addListener(映射,“mousemove”,函数(事件){
document.getElementById(“footer”).innerHTML=“鼠标X Y:”+event.pixel.toString()+”-Lat Lng:“+event.latLng.toString()+”
” }); } google.maps.event.addDomListener(窗口“加载”,初始化);
最新版本的FF v39存在问题。以前在v38.0.5中工作过

我可以确认以下内容是否被窃听,给定一个具有固定大小和64px边距的地图,“Hello World!”仅当您将鼠标指针相对于标记放置在-64,-64时才会出现。在Maps中,指针位置相对于Firefox客户端区域的左上角偏移了map元素的x/y

最近几天出现了这个问题

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <title>Simple markers</title>
    <style>
      #map-canvas
      {
        width: 640px;
        height: 480px;
        margin: 64px;
      }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true"></script>
    <script>
function initialize() {
  var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
  var mapOptions = {
    zoom: 4,
    center: myLatlng
  }
  var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

  var marker = new google.maps.Marker({
      position: myLatlng,
      map: map,
      title: 'Hello World!'
  });
}

google.maps.event.addDomListener(window, 'load', initialize);

    </script>
  </head>
  <body>
    <div id="map-canvas"></div>
  </body>
</html>

简单标记
#地图画布
{
宽度:640px;
高度:480px;
利润率:64px;
}
函数初始化(){
var mylatng=new google.maps.LatLng(-25.363882131.044922);
变量映射选项={
缩放:4,
中心:myLatlng
}
var map=new google.maps.map(document.getElementById('map-canvas'),mapOptions);
var marker=new google.maps.marker({
职位:myLatlng,
地图:地图,
标题:“你好,世界!”
});
}
google.maps.event.addDomListener(窗口“加载”,初始化);

创建标记时,请使用选项{optimized:false}。它解决了firefox 39.0中的问题

    <!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <title>Simple markers</title>
    <style>
      #map-canvas
      {
        width: 640px;
        height: 480px;
        margin: 64px;
      }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true"></script>
    <script>
function initialize() {
  var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
  var mapOptions = {
    zoom: 4,
    center: myLatlng
  }
  var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

  var marker = new google.maps.Marker({
      position: myLatlng,
      map: map,
      title: 'Hello World!',
      optimized: false
  });
}

google.maps.event.addDomListener(window, 'load', initialize);

    </script>
  </head>
  <body>
    <div id="map-canvas"></div>
  </body>
</html>

简单标记
#地图画布
{
宽度:640px;
高度:480px;
利润率:64px;
}
函数初始化(){
var mylatng=new google.maps.LatLng(-25.363882131.044922);
变量映射选项={
缩放:4,
中心:myLatlng
}
var map=new google.maps.map(document.getElementById('map-canvas'),mapOptions);
var marker=new google.maps.marker({
职位:myLatlng,
地图:地图,
标题:“你好,世界!”,
优化:错误
});
}
google.maps.event.addDomListener(窗口“加载”,初始化);

如前所述-此错误随
FF 39潜入

在您的示例中,将
v=3.exp
参数替换为
v=3

是的

src="https://maps.googleapis.com/maps/api/js?v=3"

解决方案:

调用google maps api后添加参数v=3。用户4974882提供的小提琴正在调用3.exp-不起作用

作品:

<script src="https://maps.googleapis.com/maps/api/js?v=3"></script>

无法正常工作:

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script src="https://maps.googleapis.com/maps/api/js"></script>

(来自用户4974882的两个小提琴)

背景:


Firefox版本39出现问题。Mozilla团队实现了一些关于offsetX/Y的新功能(https bugzilla.Mozilla.org/show_bug.cgi?id=69787)。不幸的是,谷歌地图API已经在某种程度上解决了这个问题(https code.Google.com/p/gmapsapi issues/issues/detail?id=8278),因此,一旦推出FF39,问题就出现了。

在FF(38.0.5)中对我来说是正确的,太棒了,谢谢。看起来Firefox从v38到39的版本更改有问题。这个错误几天前在Bugzilla中添加了:google maps polygons with
mouseover
listeners也有同样的问题。它也适用于firefox 38.0.5版本。