“google.maps.MapTypeId is undefined” when using GMAP3 in FF 14

大憨熊 提交于 2019-12-12 14:51:41

问题


Testing the sample code from gmap3:

<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>

on FF 14.0.1, it gives the alert:

TypeError: google.maps.MapTypeId is undefined

on Chrome 16.0.889.0, a div with image shows up.

Why is there such a difference?


回答1:


You can try naming your function that initializes the map and then put it as callback in the link loading Google Maps api.

Something like this:

<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>

Original answer from here: Google Maps API v3 - TypeError... https://stackoverflow.com/a/8361021/1266136




回答2:


might be a little late, but for me it helped adding this line:

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

before you call mapTypeId: google.maps.MapTypeId.TERRAIN

Like this:

 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
                }
              }
              );


来源:https://stackoverflow.com/questions/11972331/google-maps-maptypeid-is-undefined-when-using-gmap3-in-ff-14

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!