Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.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
Google maps api 3 谷歌地图API集群标记问题_Google Maps Api 3 - Fatal编程技术网

Google maps api 3 谷歌地图API集群标记问题

Google maps api 3 谷歌地图API集群标记问题,google-maps-api-3,Google Maps Api 3,我在创建聚集标记时遇到问题。到目前为止,我只能看到标记本身。我尝试在for循环之前创建marker cluster,但这并不能解决问题 function codeAddress() { var markers = []; var address = ['Reston, VA'] address.push('Herndon, VA'); address.push('San Francisco, CA')

我在创建聚集标记时遇到问题。到目前为止,我只能看到标记本身。我尝试在for循环之前创建marker cluster,但这并不能解决问题

function codeAddress() {
          var markers = [];
          var address = ['Reston, VA']
          address.push('Herndon, VA');
          address.push('San Francisco, CA')
          address.push('San Jose, CA')
          for(i = 0; i < address.length; i++){
            geocoder.geocode( { 'address': address[i]}, function(results, status) {
            if (status == 'OK') {
              var marker = new google.maps.Marker({
                  map: map,
                  position: results[0].geometry.location,
                  icon: image
              });
            } else{
              alert('Geocoding did not work' + status);
            }
            markers.push(marker);
          });
        }
        const imagePath = "m1.png";
        const markerClusterer = new MarkerClusterer(map, markers, {imagePath: imagePath},{
          maxZoom: 5
        });
        markerClusterer.addMarker(marker);
      }
函数代码地址(){
var标记=[];
变量地址=['Reston,VA']
地址:push('Herndon,VA');
地址:推送('加利福尼亚州旧金山')
地址:push(加利福尼亚州圣何塞市)
对于(i=0;i

地理编码器是异步的。将标记数组添加到markerClusterer时,该数组为空

在循环之前创建MarkerClusterer,然后移动
MarkerClusterer.addMarker(marker)在geocoder回调例程中

function codeAddress() {
  var markers = [];
  var address = ['Reston, VA']
  address.push('Herndon, VA');
  address.push('San Francisco, CA')
  address.push('San Jose, CA')
  const markerClusterer = new MarkerClusterer(map, [], {
    imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m',
    maxZoom: 5
  });
  for (i = 0; i < address.length; i++) {
    geocoder.geocode({
      'address': address[i]
    }, function(results, status) {
      if (status == 'OK') {
        var marker = new google.maps.Marker({
          map: map,
          position: results[0].geometry.location
        });
        markers.push(marker);
        markerClusterer.addMarker(marker);
      } else {
        alert('Geocoding did not work' + status);
      }
    });
  }
}

你能描述一下你想看到什么吗?