谷歌地图上的JSON循环和标记只显示了一个

谷歌地图上的JSON循环和标记只显示了一个,json,google-maps-api-3,Json,Google Maps Api 3,嗨,我有一个包含多个标记的JSON数组上的循环。我不知道为什么,但我只能显示一个标记。这是密码 function plotMarkers(northEastLat,northEastLong,southWestLat,southWestLong){ jQuery.ajax({ url: 'geocoder.php', dataType:'json', type: "POST", data: { nelat: northEastLat,

嗨,我有一个包含多个标记的JSON数组上的循环。我不知道为什么,但我只能显示一个标记。这是密码

function plotMarkers(northEastLat,northEastLong,southWestLat,southWestLong){  

jQuery.ajax({
    url: 'geocoder.php',
    dataType:'json',
    type: "POST",
    data: {
        nelat: northEastLat,
        nelong: northEastLong,
        swlat: southWestLat,
        swlong: southWestLong
    },
}).done(function(brArray) {

   if (brArray == undefined || brArray == null || brArray.length == 0){
        //no elements around you

    } else {

        $(jQuery.parseJSON(JSON.stringify(brArray))).each(function() {  

            var NAME = this.name;
            var LATITUDE = this.latitude;
            var LONGIT = this.longit;
            var ADDRESS = this.address;
            var NAMEELEMENT = this.nameelement;

            var infowindow = new google.maps.InfoWindow({
                content: NAME + '<br>' + NAMEELEMENT  + '<br>' + ADDRESS
            });

            var latLng = new google.maps.LatLng(LATITUDE, LONGIT); 
            // Creating a marker and putting it on the map
            marker = new google.maps.Marker({
                position: latLng,
                map: map,
                icon: 'img/marker.png',
                title: NAME + ' - ' + NAMEELEMENT
            });

            marker.setMap(map);
            google.maps.event.addListener(marker, 'click', function() {
                infowindow.open(map,marker);
            });
        });         

    }
}); 

您可以发布更多的代码或提供一个可供使用的实例吗?为什么要调用
JSON.stringify
只是为了
jQuery.parseJSON
it?我使用JSON.stringify只是为了解析它?我放了更多的代码,我正在尝试这个函数locallyCan你能发布JSON吗?代码中没有任何东西可以解释这种行为。我刚刚意识到JSON数组只包含一个元素,而不是预期的两个。我测试了geocoder.php文件中的while循环以及数据库上的查询,结果都给出了两个元素。我使用console.dir(brArray)打印的对象给了我以下结果:
对象地址:“595 Burrard Street”纬度:“49.28582459”longit:-123.119431973”名称:“邮局”名称元素:“元素测试”
好的,我解决了这个问题,主要问题是在php文件的while循环中。生成数组的循环。所以问题与标记无关。
google.maps.event.addListener(map, 'idle', function() {
 plotMarkers(map.getBounds().getNorthEast().lat(), map.getBounds().getNorthEast().lng(), map.getBounds().getSouthWest().lat(), map.getBounds().getSouthWest().lng());  
});