chrome cannot read property

场景:Chrome下使用百度map报错Cannot read property 'minZoom' of undefined

Chrome下使用百度地图报错Cannot read property 'minZoom' of undefined

 

问题:工作中在Google chome下面的js console里面测试百度地图API

var map = new BMap.Map("container");

 
map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);
 
TypeError: Cannot read property 'minZoom' of undefined
  1. message"Cannot read property 'minZoom' of undefined"
  2. stack(...)
  3. get stackfunction () { [native code] }
  4. set stackfunction () { [native code] }
  5. __proto__Error

 

解决办法:把js代码放到地图DIV容器的下面即可。

Html代码  chrome cannot read property
  1. ...  
  2. ...  
  3. <body>  
  4.     <div id="mymap"></div>  
  5.     <script type="text/javascript">   
  6.         var map = new BMap.Map("mymap");
  7.         map.centerAndZoom(new BMap.Point(123.404, 39.815),11);
  8.     </script>  
  9. </body>  
  10. ...  
  11. ...