【问题标题】:How do I use link in google maps如何在谷歌地图中使用链接
【发布时间】:2019-04-24 23:44:02
【问题描述】:

我目前正在尝试将 link_to 添加到我地图上的价格中。 我面临的问题是,通过单击价格,它不会将用户重定向到特定的显示页面。 例如,当我查看网址时,它不会从 /search 更改为 -> wines/1。

这是我正在尝试的代码:

wines.forEach(function(wine) {
    marker = new google.maps.Marker ({
        position: {lat: wine.latitude, lng: wine.longitude},
        map: map
    });
    windowContent = "<div class='map_price'>Ab " + wine.price + "€</div>";
    windowContent += "<div><%= escape_javascript link_to(@wine) %></div>";

    inforwindow = new google.maps.InfoWindow ({
        content: windowContent
    });

    inforwindow.open(map, marker);
});
}

【问题讨论】:

  • 变量@wine在哪里定义?你能分享你的控制器和视图的代码吗?

标签: jquery ruby-on-rails google-maps ruby-on-rails-5


【解决方案1】:

在 Rails 中呈现链接的方法有很多,并且因为您使用 javascript 来呈现 Map 上的所有葡萄酒(我希望每个 wine 都包含 id 以及其他详细信息),我建议改用 anchor 标签Rails 的link_to 方法如下...

wines.forEach(function(wine) {
    marker = new google.maps.Marker ({
        position: {lat: wine.latitude, lng: wine.longitude},
        map: map
    });
    windowContent = "<div class='map_price'>Ab " + wine.price + "€</div>";
    windowContent += "<div><a href='http://yourdomain.com/wines/'+wine.id target='_blank'>View</a></div>";

    inforwindow = new google.maps.InfoWindow ({
        content: windowContent
    });

    inforwindow.open(map, marker);
});

【讨论】:

    猜你喜欢
    • 2012-03-23
    • 1970-01-01
    • 2015-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-13
    • 1970-01-01
    相关资源
    最近更新 更多