firefox中的Google地图mouseevent显示不正确的坐标
google map mouseevent in firefox shows incorrect coordinates
我有一个google地图api页面,当地图div不在浏览器窗口的左上角(0,0)时,它没有从firefox中的鼠标事件返回正确的坐标。如果我在地图div上放置任何css填充或边距,那么谷歌地图中的鼠标事件起源仍然从浏览器窗口的左上角开始,而不是地图div。Chrome返回正确的lat/lng,但Firefox没有。有人有什么建议吗?
我在http://jsfiddle.net/fNPvf/15426/创建了一个非常简单的示例,它显示了鼠标在地图上移动时的坐标。你可以看到在地图图像的左上角,坐标应该是0,0,但是Firefox显示的是50,50。信息窗口显示了地图中心的正确位置,当您将鼠标移动到该点时,您可以看到坐标的差异(向左上角移动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>
解决方案:
在调用google maps api时添加参数v=3。user4974882提供的小提琴正在调用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>
实例
(from user4974882)
背景:Firefox版本39出现问题。mozilla团队实现了一些关于偏移x/Y的新功能(https bugzilla.mozilla.org/show_bug.cgi?id=69787)。不幸的是,Google Maps API已经在某种程度上解决了这个问题(https code.google.com/p/gmaps-api-issues/issues/detail?id=8278),所以-一旦FF39推出-问题就出现了。
最新版本FF v39的问题。以前在v38.0.5中工作过。
我可以确认下面是bug,给定一个固定大小和64px边距的地图,"Hello World!"只会在你将鼠标指针放置在相对于标记的-64,-64时出现。似乎在Maps中,指针的位置被map元素相对于Firefox客户端区域左上角的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>
创建标记时使用选项{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>
如上所述-这个bug是在FF 39
中出现的。
在您的示例中,将v=3.exp
参数替换为v=3
所以应该是
src="https://maps.googleapis.com/maps/api/js?v=3"
- Jquery菜单操作不稳定,定位不正确,存在一般错误
- Amazon S3 REST API大小不正确
- Javascript Reg Exp不正确匹配
- DIV并排,位置不正确
- 仅在IE中,javascript中的时区名称不正确
- 注意:wp_enqueue_script调用不正确.在 Wordpress 调试模式下
- 你能解释一下为什么这个javascript不正确吗
- 从int值来看,Javascript日期不正确
- jQuery-迭代不正确?(太长,无法执行)
- 字符串解析不正确
- 日历显示不正确
- 引导程序下拉列表显示不正确
- Node.js:多个然后'It’执行顺序不正确
- Highcharts热图显示不正确
- D3JS 图绘制在不正确的坐标处
- 开放层 - 像素坐标不正确
- 为什么Raphael.js的动画设置到不正确的坐标
- css缩放的谷歌地图点击不正确的坐标
- firefox中的Google地图mouseevent显示不正确的坐标
- 谷歌地图坐标不正确