Reputation: 2793
I'm new to Ruby on Rails (about 2 months at it). I've got a project to complete, which I think should be fairly simple, but is proving to be frustrating.
I have a Contact Page, where I want to say 'We are located here!', with a Google Map of where the business is. That's all.
In Javascript I'd put a map div in my html page and link to my js file etc...can someone tell me the equivalent of what I need to do in my Rails 3 project? I looked at some stuff out there but it had to do with Rails 2 or 1.8, and I don't want to risk putting it in and messing up my project.
Thanks for any help,
Chris.
Upvotes: 0
Views: 199
Reputation: 13611
If you want to use an interactive map, it's all javascript code. When you have your lat & lng values of the office, you can do something like the following:
<div id="map"></div>
In the html, and have in your javascript (jquery).
$.fn.ready(function() {
var lat = 10.0000; // change to your value
var lng = 10.0000; // change to your value
var bounds = new google.maps.LatLngBounds();
var map = new google.maps.Map(document.getElementById("map"), { zoom: 5, mapTypeId: google.maps.MapTypeId.ROADMAP, center: new google.maps.LatLng(parseFloat(lat), parseFloat(lng)) });
var lat_lng = new google.maps.LatLng(parseFloat(point.lat), parseFloat(point.lng));
var marker = new google.maps.Marker({
position: lat_lng,
title: "point"
});
marker.setMap(map);
bounds.extend(lat_lng);
map.fitBounds(bounds);
});
I haven't tested the code. I kind of grabbed some logic i had from a project where i rendered several points on the map, and it was also in coffeescript, so i'm not sure if i missed anything. In short though, it's all the googlemaps api.
Upvotes: 1