开发者社区> 问答> 正文

我想在地图上增加点。但是我的代码有问题

html,正文{高度:100%;边距:0; 填充:0; } #map {高度:100%;} //创建一个map变量var map; var markers = []; //用于在地图div函数initMap(){map = new google.maps.Map(document.getElementById('map'),{center:{lat:40.74135,lng:-73.99802},缩放:)中初始化地图的函数: 14});

    {title: 'Markerul', location: {lat: 40,7713024, lng: -73.9632393}}
  ];

  var largeInfowindow = new google.maps.InfoWindow();
  for(var i = 0; i<locations.length; i++){
    var positions = locations[i].location;
    var title = locations[i].title;
    var marker = new google.maps.Marker({
      map: map,
      position: position,
      title: title,
      animation: google.maps.Animation.DROP,
      id: i
    });
    markers.push(marker);
    // onclick
    marker.addListener('click', function (){
      populateInfoWindow(this, largeInfowindow);
    });
  }

  function populateInfoWindow(marker, infowindow){
    // verifica daca fereastra de info nu este deja deschisa
    if(infowindow.marker !=marker){
      infowindow.marker = marker;
      infowindow.setContent('<div>' + marker.title + '</div>');
      infowindow.open(map, marker);
      infowindow.addListener('closeclick', function(){
        infowindow.setMarker(null);
      });
    }
  }

  var largeInfowindow = new google.InfoWindow();
  var bounds = new google.maps.LatLngBounds();
  // crearea unei arii de markere
  for (var i = 0; i < locations.length; i++){
    // ia pozitia 
    var position = locations[i].location;
    var title = locations[i].title;
    //crearea unui marker per locatie si punerea lui in aria de markere
    var marker = new google.maps.Marker({
      map: map,
      position: position,
      title: title,
      animation: google.maps.Animation.DROP,
      id: i
    });
    //push the marker to our array of markers
    markers.push(marker);
    //extinderea ariei pt markere
    bounds.extend(marker.position);
    //onclick
    marker.addListener('click', function (){
      populateInfoWindow(this, largeInfowindow);
    });
  }
  map.fitBounds(bounds);
 }

展开
收起
社区秘书 2019-12-05 16:13:33 659 0
0 条回答
写回答
取消 提交回答
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
复杂环境下的视觉同时定位与地图构建 立即下载
《解决方案A4折页-游戏_复制》 立即下载
动态、高效,蚂蚁动态卡片的内核逻辑 立即下载