initMap不是一个函数 [英] initMap is not a function

查看:1598
本文介绍了initMap不是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白是什么问题?我使用Google Map API中的这个示例:简单地图

 < body> 
<! - 地图部分 - >
< section id =map>< / section>

< script src =js / jquery.min.js>< / script>
< script src =js / main.js>< / script>
< script src =https://maps.googleapis.com/maps/api/js?key=AIzaSyB5Y8CqFe-4Egzl5TlPqlFvjRGcuCfHGvY&callback=initMapasync defer>< / script>

< / body>

main.js:

  // ----------------------------------------- --------- 
//联系地图
// --------------------------- -----------------------
函数initMap(){
if($(#map)。length> 0 )
{
var map;
map = new google.maps.Map(document.getElementById('map'),{$ b $ center:{lat:44.4297538,lng:26.0649221},
zoom:16,
scrollwheel:false,
zoomControl:false,
panControl:false,
streetViewControl:false,
mapTypeControl:false,
overviewMapControl:false,
clickable :false
});


$ b

错误:


message:initMap不是函数



name:InvalidValueError



解决方案

同样的问题,我个人删除了& callback = initMap 来使它工作。
其他线程显示initMap是你应该自己构建的函数。


I can't understand what is the problem? I used this example from Google Map APIs: Simple Map

<body>
   <!-- Map Section -->
   <section id="map"></section>

   <script src="js/jquery.min.js"></script>
   <script src="js/main.js"></script>
   <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB5Y8CqFe-4Egzl5TlPqlFvjRGcuCfHGvY&callback=initMap" async defer></script>

</body>

main.js:

//--------------------------------------------------
// Contact Map
//--------------------------------------------------
function initMap() {    
    if ($("#map").length > 0)
    {
        var map;
        map = new google.maps.Map(document.getElementById('map'),{
            center: {lat: 44.4297538, lng: 26.0649221},
            zoom: 16,
            scrollwheel: false,
            zoomControl: false,
            panControl: false,
            streetViewControl: false,
            mapTypeControl: false,
            overviewMapControl: false,
            clickable: false
        });

    }
}

Error:

message: "initMap is not a function"

name: "InvalidValueError"

解决方案

Having the same issue, I personally removed the &callback=initMap to make it work. Other threads seams to show that initMap is a function you should build yourself.

这篇关于initMap不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆