0

我正在使用带有很多标记的 Google Maps API V3 创建一个 ASP.NET MVC3 网站。每个标记都有一个信息窗口,其中包含有关此地点的一些信息。

我希望每个标记都有一个直接链接,可以直接在这个标记上访问我的网站,例如http://www.mywebsite/1589。因此,用户可以使用以标记 1589 为中心的地图访问网站,并且其 InfoWindows 将打开。

标记已经在地图上,并且它们的信息窗口已经在显示信息,但我不知道如何创建到标记的直接链接......有人可以帮我吗?

提前致谢

4

1 回答 1

2

关键部分是:

  • 解析查询字符串

    // skip the first character, we are not interested in the "?"
    var query = location.search.substring(1);
    
    // split the rest at each "&" character to give a list of  "argname=value"  pairs
    var pairs = query.split("&");
    for (var i=0; i<pairs.length; i++) {
      // break each pair at the first "=" to obtain the argname and value
      var pos = pairs[i].indexOf("=");
      var argname = pairs[i].substring(0,pos).toLowerCase();
      var value = pairs[i].substring(pos+1).toLowerCase();
    
      // process each possible argname  -  use unescape() if theres any chance of spaces
      if (argname == "id") {id = unescape(value);}
      if (argname == "marker") {index = parseFloat(value);}
    }
    
  • 如果传递了参数,则在加载标记后打开信息窗口

      // ========= If a parameter was passed, open the info window ==========
      if (id) {
        if (idmarkers[id]) {
          google.maps.event.trigger(idmarkers[id],"click");
        } else {
          alert("id "+id+" does not match any marker");
        }
      }
      if (index > -1) {
        if (index < gmarkers.length) {
          google.maps.event.trigger(gmarkers[index],"click");
        } else {
          alert("marker "+index+" does not exist");
        }
      }
    
  • 您可能还需要此示例中的“链接到”功能,它设置查询字符串

于 2013-09-16T15:46:42.400 回答