【问题标题】:jQuery GoogleMap FirefoxjQuery 谷歌地图 火狐
【发布时间】:2011-06-07 19:05:53
【问题描述】:

我尝试使用谷歌地图,它适用于 Chrome IE 但不适用于 FireFox?

我想念一些东西:

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/jscript">
function initialize() {

    var latitude = document.getElementById("Latitude").value;
    var longitude = document.getElementById("Longitude").value;

    var latlng = new google.maps.LatLng(latitude, longitude);
    var options = { zoom: 16, center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById
        ("map_canvas"), options);
    var image = '@Url.Content("~/Images/pushpin.png")';
    var marker = new google.maps.Marker({
        position: latlng,
        title: "Position",
        icon: image

    });
    marker.setMap(map);
}

$(function () {
    initialize();

});
</script>
<div id="map_canvas" style="width: 800px; height: 400px;margin-top:15px;">

【问题讨论】:

  • 这对我来说是正确的。你的map_canvascss 是什么?此外,它是否会在 FF 中生成任何内容(部分地图或灰色地图空间?)
  • 我的 map_canvas 是一个简单的 div
  • hmm.. 通常问题是没有指定高度和宽度。如果删除标记会发生什么?它在 FF 中有效吗?
  • 即使我删除了标记,也是同样的问题。 div 在这里,但地图不在
  • 如果您有萤火虫,请尝试在该控制台中调用initialize,然后查看它是否加载。不久前我有一个非常相似的问题。我正在制作带有多个标记的地图,但它出错了。为我解决的问题是在创建地图后立即设置所有边界和所有标记,但我认为这不是你的问题。

标签: jquery jquery-ui firefox google-maps


【解决方案1】:

您的 jquery 调用看起来很可疑。我会尝试:

$(document).ready(function() {
 initialize();
});

我只是坚持使用讨厌的旧内联 onload="initialize()"。如果您想要一个工作示例,您可以查看我所拥有的 here

【讨论】:

  • 那里没有任何“可疑”之处,$(function() { })$(document).ready(function() { }) 完全相同。再回过头来添加onload 属性也不是一种改进。
  • onload 并不是真正的建议,更多的是承认。我没有看到文件准备好的速记。整洁的。仍然提供的链接可能会有所帮助。
猜你喜欢
相关资源
最近更新 更多
热门标签