Display hydrants on the map
This commit is contained in:
parent
322e6403bb
commit
2210857387
|
@ -1,12 +1,14 @@
|
||||||
class WelcomeController < ApplicationController
|
class WelcomeController < ApplicationController
|
||||||
def index
|
def index
|
||||||
|
@zoom = 15
|
||||||
# Default coordinates: Boston center
|
# Default coordinates: Boston center
|
||||||
@lat, @lng = 42.358431, -71.059773
|
@lat, @lng = 42.358431, -71.059773
|
||||||
@zoom = 15
|
@hydrants = []
|
||||||
address, city, state = params[:address], params[:city], params[:state]
|
address, city, state = params[:address], params[:city], params[:state]
|
||||||
if address && city && state
|
if address && city && state
|
||||||
@lat, @lng = Address.find_lat_lng("#{address}, #{city}, #{state}")
|
|
||||||
@zoom = 18
|
@zoom = 18
|
||||||
|
@lat, @lng = Address.find_lat_lng("#{address}, #{city}, #{state}")
|
||||||
|
@hydrants = Hydrant.find_closest(@lat, @lng)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,6 +16,17 @@
|
||||||
mapTypeId: google.maps.MapTypeId.ROADMAP
|
mapTypeId: google.maps.MapTypeId.ROADMAP
|
||||||
};
|
};
|
||||||
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
|
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>
|
</script>
|
||||||
<%= csrf_meta_tag %>
|
<%= csrf_meta_tag %>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<p id="tagline">
|
<p id="tagline">
|
||||||
Claim responsibility for shoveling out a fire hydrant after it snows.
|
Claim responsibility for shoveling out a fire hydrant after it snows.
|
||||||
</p>
|
</p>
|
||||||
<%= form_tag root_path, :method => :get do %>
|
<%= form_tag do %>
|
||||||
<%= label_tag "address" %>
|
<%= label_tag "address" %>
|
||||||
<%= text_field_tag "address", params[:address], :tabindex => 1 %>
|
<%= text_field_tag "address", params[:address], :tabindex => 1 %>
|
||||||
<%= label_tag "city" %>
|
<%= label_tag "city" %>
|
||||||
|
|
Loading…
Reference in New Issue