Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 谷歌地图API添加了超过10个标记_Javascript_Google Maps - Fatal编程技术网

Javascript 谷歌地图API添加了超过10个标记

Javascript 谷歌地图API添加了超过10个标记,javascript,google-maps,Javascript,Google Maps,我正试图使用以下代码在谷歌地图上添加批量标记 var map = null; var geocoder = null; var bounds = null; var gdir; var properties_address = new Array(); var blueIcon = new GIcon(G_DEFAULT_ICON); blueIcon.iconSize = new GSize(26, 33); markerOptions = { icon:blueIcon }; blueIc

我正试图使用以下代码在谷歌地图上添加批量标记

var map = null;
var geocoder = null;
var bounds = null;
var gdir;

var properties_address = new Array();
var blueIcon = new GIcon(G_DEFAULT_ICON);
blueIcon.iconSize = new GSize(26, 33);
markerOptions = { icon:blueIcon };
blueIcon.image = "https://mysite/images/marker.gif";

properties_address = ["Abohar,Punjab,india", "Achhalda,Uttar Pradesh,india", "Achhnera,Uttar Pradesh,india", "Adari,Uttar Pradesh,india", "Adilabad,Andhra Pradesh,india", "Adipur,Gujarat,india", "Adoni,Andhra Pradesh,india", "Adoor,Kerala,india", "Agartala,Tripura,india", "Agra,Uttar Pradesh,india", "Ahmedabad,Gujarat,india", "Ahmedgarh,Punjab,india", "Ahmednagar,Maharashtra,india", "Aizawl,Mizoram,india", "Ajmer,Rajasthan,india", "Akaltara,Chhattisgarh,india", "Akola,Maharashtra,india", "Alappuzha,Kerala,india"];

$(document).ready(function() {
    bounds = new GLatLngBounds;
    initialize();
 });

 function initialize() {
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(21.88, 78.442626), 5);
        geocoder = new GClientGeocoder();
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());

        $.each(properties_address, function(index, property) {
          showAddressByAddress(index, property, false);
        });                        
    }
}

function showAddressByAddress(index,address, is_custom)
{
    if(address){
        geocoder.getLatLng(address,function(point) {
            var marker = new GMarker(point,markerOptions);
            map.addOverlay(marker);
            bounds.extend(marker.getPoint());
            map.setZoom(map.getBoundsZoomLevel(bounds));
            map.setCenter(bounds.getCenter());

            GEvent.addListener(marker, "mouseover", function() {
                if(!is_custom){
                    address_html = address + '<br /><a id="route_'+index+'" href="#" class="route_url" data-address="'+ address +'">Route from here</a>';
                }else{
                    address_html = address;
                }

                marker.openInfoWindowHtml(address_html);
            });               

        });
    }
}
在我在properties\u address数组中为它提供10个地址之前,代码运行良好,但超过10个地址会导致以下错误

a is null http://maps.gstatic.com/intl/en_ALL/mapfiles/377a/maps2.api/main.js Line 1131
您是否尝试过使用firebug查看数组的属性?听起来数组中的某个项为空

<html>
<script type="text/javascript">
var myCars=["Saab","Volvo","BMW"];;
console.log(myCars);    
</script>
</html>`
然后在firebug控制台窗口中查看阵列的属性 数组名称错误:

var properties_add21ress = new Array();

它是固定的,我只是跳过了地理代码找不到的点

function showAddressByAddress(index,address, is_custom)
{
    if(address){
        geocoder.getLatLng(address,function(point) {
            if(point){
                var marker = new GMarker(point,markerOptions);

                map.addOverlay(marker);
                bounds.extend(marker.getPoint());
                map.setZoom(map.getBoundsZoomLevel(bounds));
                map.setCenter(bounds.getCenter());


                GEvent.addListener(marker, "mouseover", function() {
                    if(!is_custom){
                        address_html = address + '<br /><a id="route_'+index+'" href="#" class="route_url" data-address="'+ address +'">Route from here</a>';
                    }else{
                        address_html = address;
                    }

                    marker.openInfoWindowHtml(address_html);
                });

            }
        });
    }

示例代码是否在main.js之上?其中是一个?'a is null'是一个典型的错误,当您自己的代码中出现JS错误时,您会从Google Maps javascript中得到。您可以向我们展示第11个数组项的内容吗?您应该考虑移动到Maps API的第3版,这是第2版代码。【阿博哈尔、旁遮普、印度、阿查尔达、北方邦、印度、阿赫内拉、北方邦、印度、阿达里、北方邦、印度、阿迪拉巴德、安得拉邦、印度、阿迪普尔、古吉拉特邦、印度、阿多尼、安得拉邦、印度、阿多尔、喀拉拉邦、印度、阿加塔拉、特里普拉、印度、阿格拉、北方邦、印度、艾哈迈达巴德、古吉拉特邦、印度、艾哈迈德加、旁遮普、印度、艾哈迈德纳加尔、马哈拉施特拉邦、印度、艾扎瓦勒、米兹】奥拉姆、印度、阿杰梅尔、拉贾斯坦邦、印度、阿卡塔拉、恰蒂斯加尔、印度、阿科拉、马哈拉施特拉邦、印度、阿拉布扎、喀拉拉邦]这只是发问时的拼写错误,但这不是问题所在。谢谢你的回复。