Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Get google maps integrated with your app -minimal code
#------ application layout
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<%= javascript_include_tag "jquery", "jquery-ui","rails" %>
<%= javascript_include_tag "application" %>
<script type="text/javascript">
<%= yield(:javascript)%>
var initialLocation;
//example of a location/point
var newyork = new google.maps.LatLng(40.69847032728747, -73.9514422416687);
var browserSupportFlag = new Boolean();
var map;
var infowindow = new google.maps.InfoWindow();
function initialize_map(points, centerpoint) {
var myOptions = {
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP
// map_canvas must be a div on your page
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
for(var i=0; i < points.length; i++) {
var marker = new google.maps.Marker({
position: points[i],
map: map
# ---- a view in your app that pulls a list of locations possibly stored in a db
<% content_for(:javascript) do %>
locations = [];
<% @locations.each do |loc|%>
locations.push(new google.maps.LatLng(<>, <%=loc.lon%>));
$(function() {
// make second argument to whatever the map should be centered on
initialize_map(locations, locations[0]);

mmclead commented Jul 6, 2011

Thanks for the gist. Unfortunately, I've been unable to get this to work. I'm seeing that my app is loading the google maps .js file but no map is displayed. The last thing my pages loads is js from AuthenicationService.Authenticate that happens 4 seconds after everything else.
Any help would be greatly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment