有没有办法使用gmaps4rails gem查看标记,具体取决于当前用户登录?我不确定它是否有可能已经解决,但我尝试组合使用康康宝石,但它只会导致所有标记消失。不幸的是,我不知道如何继续。所以我想要实现的是根据当前登录的用户使标记可见。我很感激任何帮助!
关系控制器的当前代码:
def index
@relations = Relation.all
@hash1 = Gmaps4rails.build_markers(@relations) do |relation, marker|
# something like "if current_user == relation.user_id" ?
marker.lat relation.childlat
marker.lng relation.childlng
marker.picture({
:url => ActionController::Base.helpers.image_path("childgross.png"),
:width => "45",
:height => "45"
})
end
@hash2 = Gmaps4rails.build_markers(@relations) do |relation, marker|
marker.lat relation.kigalat
marker.lng relation.kigalng
marker.picture({
:url => ActionController::Base.helpers.image_path("persongross.png"),
:width => "45",
:height => "45"
})
end
end
关系索引视图中的代码:
<%=raw @hash1.to_json %>
<%=raw @hash2.to_json %>
<script>
handler = Gmaps.build('Google');
handler.buildMap({provider: {},internal: {id: 'map'}},function(){
markers = handler.addMarkers(<%=raw @hash1.to_json %>);
markers = handler.addMarkers(<%=raw @hash2.to_json %>);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
});
</script>
向@Pablo致敬它刚刚来到我身边......我只需要用@relations = Relation.all
取代@relations = Relation.where(user_id: current_user.id)