Skip to content

Instantly share code, notes, and snippets.

@rossnelson
Created January 24, 2012 15:52
Show Gist options
  • Save rossnelson/1670802 to your computer and use it in GitHub Desktop.
Save rossnelson/1670802 to your computer and use it in GitHub Desktop.
Google Map API V3 example
= render "maps/map", :map => @map
= 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;"}
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
});
}
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
@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