Javascript gomap插件,根据Web服务添加多个标记

Javascript gomap插件,根据Web服务添加多个标记,javascript,google-maps,jquery,google-maps-markers,Javascript,Google Maps,Jquery,Google Maps Markers,首先,我从以下位置使用库:, 我正在使用Web服务获取数据 我想在地图上找到这些信息,但我以前不知道我需要创建多少元素。 要获取数据,我有以下代码: $('#default-search').submit(function () { var gomap_marker = []; var search_where = $('#search-where').val(); if ($('#search-where').val() == "") sear

首先,我从以下位置使用库:, 我正在使用Web服务获取数据

我想在地图上找到这些信息,但我以前不知道我需要创建多少元素。 要获取数据,我有以下代码:

    $('#default-search').submit(function () {

    var gomap_marker = [];
    var search_where = $('#search-where').val();
    if ($('#search-where').val() == "")
        search_where = "-1";
    $.ajax({
        url: "http://my_url.com/",
        contentType: "json",
        data: {
            city: search_where
        },
        success: function (data) {

            //List received data
            $.each(data, function (index, item) {

                //create an array with data
                gomap_marker.push({
                    id: item.Id,
                    address: item.Street + ', ' + item.ZipCode + ' ' + item.City, 
                    icon: 'images/marker.png',
                    group: 'toshow',
                    html: '<a href="index.html">' + item.Street + ', ' + item.ZipCode + ' ' + item.City + '</a>'
                });
            }); // END - $.ajax success each

            // valid test
            for (var i = 0; i < gomap_marker.length; i++) {
                alert('1 - ' + gomap_marker[i].id + gomap_marker[i].address + gomap_marker[i].html);
            }

            // reset the map for each request
            $("#map").removeData();
            alert('Test');
            // map init + markers
            jQuery('#map').goMap({
                maptype: 'ROADMAP',
                zoom: 13,
                scaleControl: true,
                scrollwheel: false,
                markers: gomap_marker
            });
        }, // END - $.ajax success 
        error: function () { alert("simple request goes wrong"); }
    }); // END - $.ajax
    return false;
}); // END - default-search
$(“#默认搜索”).submit(函数(){
var gomap_标记=[];
var search_where=$('#search where').val();
if($('#搜索其中').val()=“”)
搜索_其中=“-1”;
$.ajax({
url:“http://my_url.com/",
contentType:“json”,
数据:{
城市:在哪里搜索
},
成功:功能(数据){
//列出收到的数据
$。每个(数据、功能(索引、项目){
//创建包含数据的数组
gomap_marker.push({
id:item.id,
地址:item.Street+,'+item.ZipCode+''+item.City,
图标:“images/marker.png”,
团体:"东秀",,
html:'
});
});//结束-$。每次ajax成功
//有效测试
对于(变量i=0;i
只有数组的第一行才能在地图上创建标记。我不知道如何设置其他的

我想使用$.goMap.createMarker而不是创建数组并重置贴图,但我遇到了相同的问题:只有第一行在贴图上创建了一个标记


关于,emm首先创建一个lat、long数组

    var data = new Array();
    data[0] = new Array();
    data[0][0] = 'FOOD'; //name
    data[0][1] = '23,23';//coordinates(lat,lng)

    function HTMLMarker( place ) {
           this.name = place[0];
           var latLngStrings = place[1].split(',');
           var lat = +latLngStrings[0];
           var lng = +latLngStrings[1];
           this.pos = new google.maps.LatLng( lat, lng );
    }
    HTMLMarker.prototype = new google.maps.OverlayView();
    HTMLMarker.prototype.onRemove = function () {};
    HTMLMarker.prototype.onAdd = function () {
    var div = this.div = document.createElement('DIV');
    div.className = "htmlMarker";
    div.innerHTML = '<a href="#" class="pin_on_map">'+this.name+'</a>';
                        var panes = this.getPanes();
                        panes.overlayImage.appendChild(div);
                    };
   HTMLMarker.prototype.draw = function () {
          var overlayProjection = this.getProjection();
          var position = overlayProjection.fromLatLngToDivPixel(this.pos);
          var panes = this.getPanes();
          this.div.style.left = position.x - 30 + 'px';
          this.div.style.top = position.y - 48 + 'px';
                    };

     function initialize() {
          var myLatLng = new google.maps.LatLng(23,23);
          var mapOptions = {
                            zoom: 15,
                            center: myLatLng,
                            mapTypeId: google.maps.MapTypeId.ROADMAP
                        };

     var gmap = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);

                        for (var i = 0; i < data.length; i++) {
                            addMarker( data[i] );
                        }

                        function addMarker( place ) {
                            var htmlMarker = new HTMLMarker( place );
                            htmlMarker.setMap(gmap);
                        }
                    }

                   google.maps.event.addDomListener( window, 'load', initialize );
<script>
<?php $i = 0;
foreach($places as $place) {
     $pins = $place['pins']; //coordinates
     $name = $place['name'];
     echo "data[$i] = new Array();\n";
     echo "data[$i][0] = '" .$name. "';\n";
     echo "data[$i][1] = '" .$pins. "';\n";
  $i++;
} ?>
</script>
 .htmlMarker {
    position: absolute;
}