为 gmaps4rails 制作地图标记直接链接 onclick [英] Make map marker direct link onclick for gmaps4rails

查看:46
本文介绍了为 gmaps4rails 制作地图标记直接链接 onclick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,当点击地图标记时,信息窗口显示为发生了什么",如下所示:

Currently have the infowindow showing as the 'what happens' when the map marker is clicked, as so:

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

我如何让它自动链接到标记的显示页面,即.在哪里可以放入代码参考:

How would I get this to work to automatically link to the marker's SHOW page, ie. where is it possible to put in a code reference:

<a href='/controller/#{slug}'>#{title}</a> 

<%= link_to %> function

推荐答案

针对这种需求,我向控制器中的 gmaps4rails 方法传递了一个块(此处的文档):

For this kind of needs, I pass a block to the gmaps4rails method in the controller (doc here):

@json = User.all.to_gmaps4rails do |user, marker|
  marker.json "\"id\": #{user.id}"
  # or
  marker.json "\"link\": #{method_to_create_link}"
end

通过这种方式,我可以获得创建链接或任何内容所需的任何其他信息.

This way I can have any additional information I need to create a link or anything.

也就是说,您可以通过这种方式更新您的侦听器:

That said, you could update your listener this way:

base_url = "whatever you need";
google.maps.event.addListener(marker, 'click', function(){
   window.location(base_url + marker.id);
   // or
   window.location(marker.link);
});

这篇关于为 gmaps4rails 制作地图标记直接链接 onclick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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