使用google maps api中的原生infoWindows有趣的地方

时间:2014-01-18 08:53:06

标签: google-maps google-maps-api-3 infowindow

我不知道它是怎么调用的,所以这里是屏幕。任何嵌入API的地图都有这些小标记,包括餐馆,酒店和其他当地人:

small markers on the map

当用户点击某些内容时,会有美容信息窗口,其中包含说明,电话,链接和评分:

infoWindow with locality info

那么这是什么以及如何使用它?我想用自己的控件更新这些infoWindows。

1 个答案:

答案 0 :(得分:0)

我找到了完全解决这个任务的答案。这是:Can I remove just the popup bubbles of POI's in Google Maps API v3?。 它是关于删除POI的infoWindows,但同样可以获取HTML代码,附加自己的控件等等。

我们必须重新定义google.maps.InfoWindow.set方法。例如,在这里我向POI的infoWindow插入了一个按钮:

function fixInfoWindow() {
  //Here we redefine set() method.
  //If it is called for map option, we hide InfoWindow, if "noSupress" option isnt true.
  //As Google doesn't know about this option, its InfoWindows will not be opened.
  var set = google.maps.InfoWindow.prototype.set;
  google.maps.InfoWindow.prototype.set = function (key, val) {
    var self = this;
    if (key === "map") {
      if (!this.get("noSupress")) {
        var link = $("<a href='#'>add to map</a>");
        link.click(function() {
          console.log("link clicked",self,self.getContent(),self.content);
        });
      $(this.content).find("div.gm-rev").append($("<div style='float:right;'></div>").append(link));
      }
    }
    set.apply(this, arguments);
  }
}

http://jsfiddle.net/kasheftin/935Km/ - 这是在POI infoWindow右下角附加“添加到地图”按钮的工作示例。

我们可以类似地将记录添加到任何方法,并观察用户点击POI标记时发生的事件调用堆栈:http://jsfiddle.net/kasheftin/935Km/1/