Created
January 24, 2012 15:52
-
-
Save rossnelson/1670802 to your computer and use it in GitHub Desktop.
Google Map API V3 example
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
= render "maps/map", :map => @map |
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
= content_for :js do | |
:javascript | |
var address = "#{map.address}"; | |
var content = "#{map.content}"; | |
= javascript_include_tag "http://maps.googleapis.com/maps/api/js?key=AIzaSyBwKDzf17n1wF6-Q77kl7wFKpwKcitNp8s&sensor=false", "map" | |
#map_canvas{:style => "width:#{map.width}px;height:#{map.height}px;"} |
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
document.load = gmap_init(); | |
function gmap_init() { | |
geocoder = new google.maps.Geocoder(); | |
geocoder.geocode( { 'address': address}, function(results, status) { | |
if (status == google.maps.GeocoderStatus.OK) { | |
map.setCenter(results[0].geometry.location); | |
var marker = new google.maps.Marker({ | |
map: map, | |
position: results[0].geometry.location | |
}); | |
google.maps.event.addListener(marker, 'click', function() { | |
infowindow.open(map, marker); | |
}); | |
} | |
}); | |
var myOptions = { | |
center: new google.maps.LatLng(-34.397, 150.644), | |
zoom: 13, | |
mapTypeId: google.maps.MapTypeId.ROADMAP | |
}; | |
var map = new google.maps.Map(document.getElementById("map_canvas"), | |
myOptions); | |
var infowindow = new google.maps.InfoWindow({ | |
content: content | |
}); | |
} |
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
class Map | |
attr_accessor :address, :width, :height, :content | |
def initialize(options={}) | |
@address = options[:address] | |
@width = options[:width] | |
@height = options[:height] | |
@content = options[:content] | |
end | |
end |
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
@map = Map.new({ | |
:address => "9324 Florence Dr. Sturtevant WI, 53177", | |
:content => "Hello Ross", | |
:width => 800, | |
:height => 300 | |
}) if @page.id == 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment