2012-08-15 19 views
3

使用GMAP3从gmap3测试样例代码时:“google.maps.MapTypeId是未定义” 在FF 14

<html>  
    <head> 
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>   
    <script src="http://maps.google.com/maps/api/js?sensor=false&language=zh" type="text/javascript"></script> 
    <script type="text/javascript" src="js/gmap3.js"></script> 
    <style> 
     .gmap3{ 
     margin: 20px auto; 
     border: 1px dashed #C0C0C0; 
     width: 500px; 
     height: 250px; 
     } 
    </style> 
    <script type="text/javascript"> 
     $(function(){ 
     try{ 
      $('#geoTestDiv').gmap3(
       { action: 'addMarker', 
       latLng : [46.578498,2.457275], 
       map:{ 
        center: true, 
        zoom: 14, 
        mapTypeId: google.maps.MapTypeId.TERRAIN 
       } 
       } 
      ); 
     }catch(exception){ 
      alert(exception); 
     } 
     }); 
    </script> 
    <body> 
    <div id="geoTestDiv" class="gmap3"></div> 
    </body> 
</html> 

在FF 14.0.1,它提供了警示:

TypeError: google.maps.MapTypeId is undefined

在Chrome 16.0.889.0上,带有图像的div显示出来。

为什么会有这样的差异?

回答

0

可能有点晚了,但对我来说它有助于加入这一行:

var myLatlng = new google.maps.LatLng(0.0, 0.0); 

打电话之前mapTypeId: google.maps.MapTypeId.TERRAIN

像这样:

var myLatlng = new google.maps.LatLng(0.0, 0.0); // this will somehow initialize google.maps... 
$('#geoTestDiv').gmap3(
       { action: 'addMarker', 
       latLng : [46.578498,2.457275], 
       map:{ 
        center: true, 
        zoom: 14, 
        mapTypeId: google.maps.MapTypeId.TERRAIN 
       } 
       } 
      ); 
2

您可以尝试命名你的函数初始化地图,然后将其作为回调加载到加载Google Maps API的链接中。

事情是这样的:

<script src="http://maps.google.com/maps/api/js?sensor=false&language=zh&callback=initMainMap" type="text/javascript"></script> 

<script type="text/javascript"> 
    function initMainMap(){ 
     //function body 
    } 
</script> 

原来的答复从这里:Google Maps API v3 - TypeError... https://stackoverflow.com/a/8361021/1266136