Javascript 向GMAP(谷歌地图)添加标记

Javascript 向GMAP(谷歌地图)添加标记,javascript,google-maps,google-maps-markers,colorize,Javascript,Google Maps,Google Maps Markers,Colorize,我正在尝试使用此工具:为我的谷歌地图添加颜色,以下是我的示例: 颜色很好,但现在我似乎无法添加任何标记,我已尝试将此示例代码放入: map.addMarker({ lat: -12.043333, lng: -77.028333, title: 'Lima', infoWindow: { content: '<p>HTML Content</p>' } }); map.addMarker({ 纬度:-12.043333, 液化天然气:-

我正在尝试使用此工具:为我的谷歌地图添加颜色,以下是我的示例:

颜色很好,但现在我似乎无法添加任何标记,我已尝试将此示例代码放入:

map.addMarker({ 
  lat: -12.043333,
  lng: -77.028333,
  title: 'Lima',
  infoWindow: {
    content: '<p>HTML Content</p>'
  }
 });
map.addMarker({
纬度:-12.043333,
液化天然气:-77.028333,
标题:“利马”,
信息窗口:{
内容:'HTML内容

' } });

但它似乎不起作用,我不完全确定放在哪里,甚至不确定引用是否正确。

文档中说:

var marker = new google.maps.Marker({
   position: new google.maps.LatLng(0,0),
   map: map,
   title:"Hello World!"
});

在小提琴中:

要创建标记,您需要执行以下操作:

来自您的示例的演示:

JS:

要添加信息窗口覆盖,请执行以下操作:

var contentString = '<div id="content"><h1>Overlay</h1></div>';
  var infowindow = new google.maps.InfoWindow({
            content: contentString
  });


google.maps.event.addListener(marker, 'click', function() {
          infowindow.open(map,marker);
        });
var contentString='Overlay';
var infowindow=new google.maps.infowindow({
内容:contentString
});
google.maps.event.addListener(标记'click',函数(){
信息窗口。打开(地图、标记);
});

通过将“this”用作infoWindow.open()的第二个参数,我能够使用循环


addListener是让单击工作所需的。有没有办法直接将其添加到映射而不是创建变量,我需要在循环中使用它来创建许多指针,如果您有其他问题尝试搜索它们(这实际上是一个非常常见的问题)和/或针对您的案例写一个新问题。我已经尝试过这样做,但现在当您选择另一个问题时,框不会消失。是否有任何方法可以添加小内容框(我已更新了我的问题)。我需要在循环中使用它来创建许多标记also@dersvenhesse如果我必须添加名称而不是标题怎么办?
var contentString = '<div id="content"><h1>Overlay</h1></div>';
  var infowindow = new google.maps.InfoWindow({
            content: contentString
  });


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