나는 두 보석의 도움으로이 문제를 접근하는 것 게임 모델에 두 개의 열을 추가).
(... 경로에 추가하는 것을 잊지 마세요) 이
Google-Maps-for-Rails
같은 것을 볼 수 있습니다 귀하의지도 컨트롤러 :
class Game < ActiveRecord::Base
after_save :cache_coordinates
def cache_coordinates
loc = Geocoder.coordinates(address)
return if loc.nil?
update_column(:latitude, loc[0])
update_column(:longitude, loc[1])
end
end
Gmaps의 작업을 얻기 위해 여기에 설명 된 지침을 반드시 준수
class MapsController < ApplicationController
respond_to :html, :js
def index
@geolocations = Game.all
@hash = Gmaps4rails.build_markers(@geolocations) do |geolocation, marker|
marker.lat geolocation.latitude
marker.lng geolocation.longitude
end
end
end
그리고 간단한보기는 다음과 같이 될 것이다 :
// use your API key here...
<%= javascript_include_tag "//maps.google.com/maps/api/js?v=3.23&sensor=false&libraries=geometry&key=YOURKEY" %>
<%= javascript_include_tag "//cdn.rawgit.com/mahnunchik/markerclustererplus/master/dist/markerclusterer.min.js" %>
<script>
var mapStyle = [];
var mapOptions = {};
var handler = Gmaps.build('Google',
{markers:
{clusterer: {
gridSize: 20,
maxZoom: 13
}}});
handler.buildMap({
internal: {id: 'multi_markers'},
provider: {
scrollwheel: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
}, function(){
var markers = handler.addMarkers(<%=raw @hash.to_json %>);
// some options you may or may not want to use
handler.map.centerOn([40.397, -95.644]);
handler.fitMapToBounds();
handler.getMap().setZoom(4)
});
</script>