私はを使用してGmaps4rails gem
いますが、これは私が持っているセットアップです:
def show
@items = Item.find(params[:id])
@hash = Gmaps4rails.build_markers(@items) do |item, marker|
marker.lat item.latitude
marker.lng item.longitude
marker.picture({
:url => "http://maps.google.com/mapfiles/arrow.png",
:width => 32,
:height => 32
})
end
append_cur_location
end
def append_cur_location
@hash << { :lat=>action[0], :lng=>action[1]}
end
def action
@lat_lng = cookies[:lat_lng].split("|")
end
から現在の場所を取得し、action method
およびitem
から場所を取得しitem.latitude
ていitem.longitude
ます。
ビュー/アイテム/show.html.erb
<div style='width: 800px;'>
<div id="map" style='width: 800px; height: 400px;'></div>
</div>
<script>
handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
markers = handler.addMarkers(<%=raw @hash.to_json %>);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
});
</script>
上記の設定で、現在の場所とアイテムの場所を示すマップを取得しました。また、アイテムの位置マーカーを変更することもできました。しかし、現在の場所のマーカーを変更して情報ボックスをアイテムの場所に追加する方法がわかりません。これらの変更を実装する方法はありますか?