【问题标题】:Work with native infoWindows of interesting places in google maps api使用 google maps api 中有趣地点的原生 infoWindows
【发布时间】:2014-01-18 08:53:05
【问题描述】:

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

当用户点击某些内容时,会出现带有描述、电话、链接和评分的美女信息窗口:

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

【问题讨论】:

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


【解决方案1】:

我找到了完全解决此任务的答案。这是: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 信息窗口的右下角有一个额外的“添加到地图”按钮。

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

【讨论】:

  • 这还能用吗?我正在尝试小提琴,看不到与普通 PoI InfoWindows 不同的任何东西......
  • 这和以前一样,他们只是更新了设计并更改了类名。这是更新版本,jsfiddle.net/kasheftin/935Km/119
  • 该小提琴看起来非常接近,但似乎每次打开 InfoWindow 时都会向每个 InfoWindow 添加一个额外的“添加到地图”。即点击的第一个 PoI 有一个 InfoWindow,右下角添加了 1 个“添加到地图”,第二个点击的 PoI 有 2 个“添加到地图”,第三个 3 x 等等......(我现在正在看电话所以不能轻易尝试自己调整代码来解决这个问题)
  • 是的,你是对的。我添加了第二个标志 externalLinkAlreadyAdded,现在它像以前一样工作,jsfiddle.net/kasheftin/935Km/121
  • 小提琴似乎都没有解决 OP?不知道在做什么。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-04
相关资源
最近更新 更多