javascript - Gmaps4rails Gem show 2 markers for same address -
i trying implement gmaps4rails gem
, geocoder gem
, works fine. thing @ index.html.erb
page, list boats , show map can not show more 1 marker if have more 1 same address. show like;
here locations_controller
;
def index if params[:search].present? @locations = location.near(params[:search], 5) #kac mile cevresinde aranıldıgının bilgisi bu km ile değişebilir else @locations = location.all end @hash = gmaps4rails.build_markers(@locations) |location, marker| marker.lat location.latitude marker.lng location.longitude marker.infowindow render_to_string(:partial => "/locations/my_template", :locals => { :object => location}) end end
this index.html.erb
;
<script src="//maps.google.com/maps/api/js?v=3.13&sensor=false&libraries=geometry" type="text/javascript"></script> <script src='//google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.14/src/markerclusterer_packed.js' type='text/javascript'></script> <h3>nearby locations</h3> <ul> <% @locations.each |location| %> <li><%=location.address %></li> (<%= location.distance.round(2) %> miles) <% end %> </ul> <div style='width: 800px;'> <div id="map" style='width: 800px; height: 400px;'></div> </div> <script type="text/javascript"> 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>
it shows 1 marker though have more 1 address same latitude , longitude. how can overcome it?
edit 1:
here looks like;
then zoom out;
and added said;
<script type="text/javascript"> handler = gmaps.build('google', { markers: { maxrandomdistance: 5 } }); handler.buildmap({ provider: {}, internal: {id: 'map'}}, function(){ markers = handler.addmarkers(<%=raw @hash.to_json %>); handler.bounds.extendwith(markers); handler.fitmaptobounds(); }); </script>
its problem map: cant have 2 things @ same place.
since common issue, there option in gem though:
handler = gmaps.build('google', { markers: { maxrandomdistance: integerinmeters } });
this randomize coordinates give within maxrandomdistance
distance of expected center
Comments
Post a Comment