1

我尝试在 PHP 中构建一个小的 Google Maps api,它从数据库中获取 Circles 和 Infowindows。除了在打开信息窗口后关闭它之外,其他任何方法都有效。

The Chrome Developer console throws out the following errors: GET http://maps.googleapis.com/maps/api/js/StaticMapService.GetMapImage?1m2&1i151368577549307460&2i99567197161272770&2e2&3u50&4m2&1u512&2u496&5m3&1e2&2b1&5sde-DE&token=119415 404 (Not Found) main.js:33 <- Onload

在点击红色弹出窗口时,它显示以下错误:未捕获的类型错误:对象 # 没有方法“O”

试图找出几个小时的解决方案,希望你能帮助我!

谢谢!

    <script type='text/javascript'>
        var _infoWindow = new Array();var _marker = new Array();

        function initialize()   {
            var mapOptions = {
                zoom: 50,
                center: new google.maps.LatLng(48.52039, 9.05949),
                mapTypeId: google.maps.MapTypeId.SATELLITE
            };
            var map = new google.maps.Map(document.getElementById('map'), mapOptions);


            var circles = [{"color":"fff","center":new google.maps.LatLng(48.5204, 9.05949),"radius":200}];     

            for(var circle in circles)  {
                new google.maps.Circle({
                    strokeColor: circles[circle].color,
                    strokeOpacity: 1,
                    strokeWeight: 2,
                    fillColor: circles[circle].color,
                    fillOpacity: 0.35,
                    map: map,
                    center: circles[circle].center,
                    radius: circles[circle].radius
                });
            }

            var infoWindows = [{"center":new google.maps.LatLng(48.5204, 9.05949),"content":"<h2>Juhu!<\/h2>Html<br>Content <b>erlaubt<\/b>!"}];
            var i = 0;

            for(var infoWindow in infoWindows)  {
                _infoWindow[i] = new google.maps.InfoWindow({
                    content: infoWindows[infoWindow].content
                });


                _marker[i] = new google.maps.Marker({
                    position: infoWindows[infoWindow].center,
                    map: map,
                    title:'Test'
                });


                google.maps.event.addListener(_marker[i], 'click', new Function('_infoWindow['+i+'].open(map,_marker['+i+']);'));

                i++;
            }

        }

        window.onload = function(){
            initialize();
        }
    </script>
</head>

<body>
    <div id='map' style='height:500px;width:500px;'></div>      
</body>

4

1 回答 1

1

您正在本地范围内定义地图变量(初始化),在点击处理程序中将无法访问它。

将此添加到脚本的顶部:

var map;

并从此行中删除 var 关键字:

var map = new google.maps.Map(document.getElementById('map'), mapOptions);
于 2012-06-30T04:30:10.963 回答