gmaps4rails - Rails – Geocoder and Google Maps help needed -
i've got bit of problem in app using geocoder , google maps rails. site i'm developing signs venues , addresses of venues gets saved markers on map. on front page search bar address , search radius entered. result goes map page venue markers on , if there markers within search , radius entered displays markers map autofitting include them all.
if there no markers present in search radius i've made temporary invisible marker placed @ exact search location, using geocoder can calculate nearest marker point , delete temporary marker , place new new marker @ closest point. map doesn't go south atlantic ocean if no markers in radius , can show user closest venue whatever search rather 'nothing in radius, try again'.
i'm sure way i've explained makes sound quite confusing , there better way it. want search bar goes address , includes markers in radius , if there no marker in radius snap closest marker , include markers around that.
it doesn't quite work hoped though. in controller have..
@venuesall = venue.all @myarray = array.new @search_location = venue.create(:address => params[:search]) @venuesall.each |venue| @mya = @myarray.push(@search_location.distance_from(venue)) if @search_location.distance_from(venue) != 0.0 end @myai = @mya.index(@mya.min) @closestvenuename = @venuesall[@myai].name @closestvenueaddress = @venuesall[@myai].address @search_location.destroy @new_search_location = venue.create(:address => @closestvenueaddress) @json = venue.near(@closestvenueaddress, 5, :order => :distance).to_gmaps4rails |venue, marker| marker.infowindow render_to_string(:partial => "/venue_locations/infowindow", :locals => { :venue => venue}) marker.title "i'm title" end @json_search = venue.last.to_gmaps4rails |venue, marker| marker.picture({ :picture => "", :width => 32, :height => 32 }) end
putting @json in gmaps4rails in view gives me venue markers exist in search radius. works fine if search has no markers in radius goes atlantic ocean..
putting @json_search in gmaps4rails put invisible marker @ closest venue. displays no other venues , markers invisible. if combine 2 maybe work i've tried
@json_all = @json + @json_search
as rails seems think both strings. doesn't crash doesn't work either. using methods join , merge crash though. think i've made more complex should have. entire controller bit of mess. can seen on github here. sorry long question. i'm new rails , coding in general hope question has made sense.
ok i've figured out. @new_search_location , @json_search variables unneccesary , causes unneeded overlapping marker. now, though i'm open suggestions on perhaps better way this.
Comments
Post a Comment