Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old July 19th, 2007, 05:14 PM
Newbie
 
Join Date: Jul 2007
Posts: 2
Default Restaurants Google

Hi. I've been trying to play with this for a while now but I haven't seemed to get it to work. I have a admin controller, which is scaffolded, to input the lat and long along with info. I have a restaurant controller that will display the map with the points. I can get the map to show but the points do not show.


Code: ( text )
class CreateRestaurants < ActiveRecord::Migration
def self.up
create_table :restaurants do |t|
t.column :category, :string
t.column :name, :string
t.column :address, :string
t.column :phone, :string
t.column :hours, :text
t.column :more_info, :text
t.column :latitude, :float
t.column :longitude, :float
end
end

def self.down
drop_table :restaurants
end
end

class RestaurantController < ApplicationController

def map
@restaurants = Restaurant.find :all
end
end

--index.rhtml--
<div id="map" style="width: 500px; height: 300px"></div>

--restaurant.rhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Restaurants: <%= controller.action_name %></title>
<%= stylesheet_link_tag 'scaffold' %>
<%= javascript_include_tag 'map' %>
<script src="http://maps.google.com/maps?file=api&v=2&key=KEY"
type="text/javascript"></script>
<script type="text/javascript">var restaurants=<%= @restaurants.to_json %>;</script>
</head>

<body>
<p style="color: green"><%= flash[:notice] %></p>

<%= yield %>

</body>
</html>

--map.js--
var map;
var centerLatitude = 42.733868932421856;
var centerLongitude = -84.47994947433472;
var startZoom = 16;
var markerHash = {};
var currentFocus = false;

function addMarker(latitude, longitude, id) {
var marker = new GMarker(new GLatLng(latitude, longitude));

GEvent.addListener(marker, 'click',
function() {
//marker.openInfoWindowHtml(description);
focusPoint(id);
});
map.addOverlay(marker);
return marker;
}

function init() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);

for (var i=0; i<markers.length; i++) {
//addMarker(restaurants[i].latitude, restaurants[i].longitude, restaurants[i].name);
var current = markers[i];
marker = addMarker(current.latitude, current.longitude, current.id);
markerHash[current.id]={marker:marker, address:current.address, visible:true};
}
}
}

window.onload = init;
window.onunload = GUnload;
Reply
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles