Created
November 14, 2012 22:11
-
-
Save Lordnibbler/4075215 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# view | |
<%# map %> | |
<%= gmaps(@gmap_options) %> | |
# controller | |
def dealer_locator | |
if params[:search].present? | |
# find locations within x miles of search params | |
# find all locations near the search query | |
@locations = Location.near(params[:search], params[:distance], :order => :distance) | |
@json = @locations.to_gmaps4rails do |location, marker| | |
# iterate through each result and build the marker | |
# distance = Geocoder::Calculations.distance_between(params[:search], location.address).round(1) | |
# marker.sidebar "<span>#{location.name} (#{distance} miles)</br>#{location.address}</span>" | |
marker.sidebar "<span>#{location.name}</br>#{location.address}</span>" | |
marker.infowindow " | |
<span class='name'>#{location.name}</span> | |
<span class='address'>#{location.address}</span> | |
<span class='phone'>#{location.phone}</span> | |
<span class='hours'>#{location.hours}</span>" | |
end | |
# flash notification | |
flash[:notice] = "No dealers within #{params[:distance]} miles of #{params[:search]}" if @json == "[]" | |
else | |
# show no locations | |
@json = nil | |
end | |
# set map options, and data source | |
@gmap_options = { | |
"map_options" => { | |
}, | |
"markers" => { | |
"data" => @json, | |
"options" => { | |
"list_container" => "markers_list" | |
} | |
} | |
} | |
# render the page | |
respond_to do |format| | |
format.html { render "pages/store/dealers" } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment