将Rails链接插入Google Maps信息窗口 [英] Inserting a rails link into a Google Maps infowindow

查看:75
本文介绍了将Rails链接插入Google Maps信息窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Google Maps InfoWindow中插入一个链接,以显示有关用户在我的rails应用程序中单击的点的更多信息.我当前的代码:

I would like to insert a link into the Google Maps InfoWindow to show more information about the point the user has clicked on in my rails app. My current code:

$.getJSON("/places", function(json) {
  if (json.length > 0) {
    for (i=0; i<json.length; i++) {
      var place = json[i];
      addLocation(place);
     }
  }
});

function addLocation(place) {
  var point = new GLatLng(place.lat, place.lng);
  var marker = new GMarker(point);
  map.addOverlay(marker);
  GEvent.addListener(marker, "click", function() {
    var info = place.name + "<br>[link]";
    map.openInfoWindowHtml(point, info);
  });
}

我希望该链接将用户带到该标记的页面(即/places/id),但不确定如何执行此操作……任何帮助将不胜感激!

I would like the link to take the user to the page for that marker (ie. /places/id), but am unsure of how to go about this...any help would be much appreciated!

推荐答案

我找到了另一种解决方案,从概念上讲可能会更容易一些-我可以在map.js文件中为每个位置构建适当的链接使用json数据包中输出的位置ID:

I've found another way to go about this that might be a bit easier conceptually - I can construct the appropriate link for each place in my map.js file using the place id outputted in the json packet:

<a href='/places/"+place.id+"'>Show more!</a>"

这似乎很好!

这篇关于将Rails链接插入Google Maps信息窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆