Google Maps setMap不是函数 [英] Google Maps setMap is not a function

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

问题描述

我正在处理我的Google Maps页面向我显示Firebug错误的问题. 当我在经销商地图中搜索时会触发clearLocations()函数. 但是出现了此错误:" markers [i] .setMap不是函数"

i am dealing with the Problem that my google Maps Page shows me an error in Firebug. The clearLocations() function is fired when i search within my dealer map. But this error is showing up: "markers[i].setMap is not a function"

有人知道如何解决该问题吗?我在几个论坛和论坛中进行了搜索,但是我使用的是google.maps.Marker数组,所以我找不到问题.

Does anyone know how to solve that problem? I searched in several forums and groups, but i am using a google.maps.Marker array so i can't find my problem.

提前谢谢!

代码( clearLocations()):

function clearLocations() {
infoWindow.close();
for (var i = 0; i < markers.length; i++) {
    markers[i].setMap(null);
}
markers.length = 0;
dealers.innerHTML = "";

}

代码( load()):

function load() {



map = new google.maps.Map(document.getElementById("map_canvas"), {
    //center: new google.maps.LatLng(51.30174, 10.60824),
    zoom: 10,
    mapTypeId: 'roadmap',
    mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU}
});
infoWindow = new google.maps.InfoWindow();
dealers = document.getElementById("dealers");

infoWindow = new google.maps.InfoWindow();
var bounds = new google.maps.LatLngBounds();

for (i = 0; i < markers.length; i++) {  
    marker = new google.maps.Marker({
        position: new google.maps.LatLng(markers[i][1], markers[i][2]),
        map: map
    });

    var pos = new google.maps.LatLng(markers[i][1], markers[i][2]);
    bounds.extend(pos);

    google.maps.event.addListener(marker, 'click', (function(marker, i) {
    return function() {
        infowindow.setContent(markers[i][0]);
        infowindow.open(map, marker);
    }
})(marker, i));
}
map.fitBounds(bounds);

}

推荐答案

因此,如果我理解正确,那么Markers数组就是LatLongs数组?还是它是google.maps.Marker类型的数组?如果是前者,那么它将不是任何Google地图标记,因此将没有可用的地图功能.

So, if I understand correctly, the Markers array is an array of LatLongs? Or is it an array of type google.maps.Marker? If it's the former then there won't be any maps functions available to it as it's not a Google maps marker.

一个选项可能是像这样在您放置在地图上的标记组成一个数组.

An option might be to make an array of the markers you place on the map like this.

var marker = new google.maps.Marker({
          position: new google.maps.LatLng(markers[i][1], markers[i][2]),
          map: map
         });
mapMarkers[i] = marker;

然后致电

mapMarkers[i].setMap(null)

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

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