Display hydrants on the map

This commit is contained in:
Erik Michaels-Ober 2011-02-25 16:49:45 -05:00
parent 322e6403bb
commit 2210857387
3 changed files with 16 additions and 3 deletions

View File

@ -1,12 +1,14 @@
class WelcomeController < ApplicationController
def index
@zoom = 15
# Default coordinates: Boston center
@lat, @lng = 42.358431, -71.059773
@zoom = 15
@hydrants = []
address, city, state = params[:address], params[:city], params[:state]
if address && city && state
@lat, @lng = Address.find_lat_lng("#{address}, #{city}, #{state}")
@zoom = 18
@lat, @lng = Address.find_lat_lng("#{address}, #{city}, #{state}")
@hydrants = Hydrant.find_closest(@lat, @lng)
end
end
end

View File

@ -16,6 +16,17 @@
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var redMarker = '/images/markers/red.png';
var greenMarker = '/images/markers/green.png';
<% @hydrants.each do |hydrant| %>
var h<%= hydrant.city_id %>LatLng = new google.maps.LatLng(<%= hydrant.lat %>, <%= hydrant.lng %>);
var h<%= hydrant.city_id %>Marker = new google.maps.Marker({
position: h<%= hydrant.city_id %>LatLng,
map: map,
icon: <%= hydrant.user_id ? "greenMarker" : "redMarker" %>
});
<% end %>
})
</script>
<%= csrf_meta_tag %>

View File

@ -3,7 +3,7 @@
<p id="tagline">
Claim responsibility for shoveling out a fire hydrant after it snows.
</p>
<%= form_tag root_path, :method => :get do %>
<%= form_tag do %>
<%= label_tag "address" %>
<%= text_field_tag "address", params[:address], :tabindex => 1 %>
<%= label_tag "city" %>