Skip to content

Instantly share code, notes, and snippets.

@thuss
Created June 27, 2011 16:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thuss/1049256 to your computer and use it in GitHub Desktop.
Save thuss/1049256 to your computer and use it in GitHub Desktop.
Google maps haml partial
/ Partial used on http://www.fanclasstic.com for mapping organizations
- organizations = organizations.delete_if{|o| o.latitude.nil? || o.longitude.nil?}
- if organizations.size > 0
- center = Geocoder::Calculations.geographic_center(organizations.clone)
#google-map
%script{:src => "http://maps.google.com/maps/api/js?sensor=false"}
%script{:type => "text/javascript"}
//<![CDATA[
function initialize() {
var myOptions = {
zoom: #{(organizations.size == 1) ? '15':'10'},
center: new google.maps.LatLng(#{center[0]}, #{center[1]}),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("google-map"), myOptions);
- for organization in organizations
var marker = new google.maps.Marker({
position: new google.maps.LatLng(#{organization.latitude}, #{organization.longitude}),
map: map,
title:"#{organization.name}"
});
}
function loadScript() {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://maps.google.com/maps/api/js?sensor=false&key=#{Geocoder::Configuration.api_key}&callback=initialize";
document.body.appendChild(script);
}
window.onload = loadScript;
//]]>
... haml ...
#map-column
= render :partial => "shared/map", :locals => { :organizations => [@organization] }
... haml ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment