简体   繁体   English

谷歌地图-window.initialize不是一个函数

[英]Google maps - window.initialize is not a function

getting the above error when trying to load my map. 尝试加载地图时出现上述错误。 Currently no map is displaying, and can't seem to find an answer anywhere! 目前没有地图显示,而且似乎无法在任何地方找到答案! Any help would be greatly appreciated! 任何帮助将不胜感激! My js code is as follows: 我的js代码如下:

 <script type="text/javascript" src = "/js/jquery-1.11.2.js">
                        var map = null;
                        var iLoadPoints = 0;

                        function initialize() {
                            var mapOptions = {
                                center: {lat: 54.872128, lng: -6.284874},
                                zoom: 13
                            };
                            map = new google.maps.Map(document.getElementById('map-canvas'),
                                    mapOptions);


                             jQuery(document).ready(function($){

                                $.getJSON('/markers/json', function (data) {


                                    var locations = JSON.parse(data);

                                    for (var i = 0; i < locations.length; i++) {
                                        addMarker(locations[i].lat, locations[i].lng);
                                    }
                                });
                            });

                        }


                        google.maps.event.addListenerOnce(map, 'idle', function () {
                            iLoadPoints += 1;
                            if (iLoadPoints === 2) {
                                initialize();
                            }
                        });

                        google.maps.event.addDomListener(window, 'load', function () {
                            iLoadPoints += 1;
                            if (iLoadPoints === 2) {
                                initialize();
                            }
                        });

Your jQuery(..)ready function is inside the initialize function. 您的jQuery(..)就绪函数位于initialize函数内部。 and you don't call the initialize function. 并且您不调用初始化函数。 this is wrong. 这是错误的。 It can't work. 不行

I have comment the part dependent form your configuration and added the call to the initialize function for a brief test. 我已经从您的配置中注释了零件相关的内容,并将调用添加到了初始化函数中以进行简短测试。 (see below) (见下文)

<script type="text/javascript" src = "/js/jquery-1.11.2.js">
                   var map = null;
                    var iLoadPoints = 0;

                    function initialize(){
                        var mapOptions = {
                            center: {lat: 54.872128, lng: -6.284874},
                            zoom: 13
                        };
                        map = new google.maps.Map(document.getElementById('map-canvas'),
                                mapOptions);

                         jQuery(document).ready(function($){

/*                                $.getJSON('/markers/json', function (data) {

                                var locations = JSON.parse(data);
                                for (var i = 0; i < locations.length; i++) {
                                    addMarker(locations[i].lat, locations[i].lng);
                                }
                            });*/
                        });

                    }


/*                    google.maps.event.addListenerOnce(map, 'idle', function () {
                        iLoadPoints += 1;
                        if (iLoadPoints === 2) {
                            initialize();
                        }
                    });

                    google.maps.event.addDomListener(window, 'load', function () {
                        iLoadPoints += 1;
                        if (iLoadPoints === 2) {
                            initialize();
                        }
                    });*/

                    google.maps.event.addDomListener(window, 'load', initialize);

        </script>

I think you must redesign your app.. movinge the part in jQuery..... function in a proper aree o function inside the initialize() function. 我认为您必须重新设计您的应用程序。在jQuery .....中移动零件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM