Restaurants Google

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ryt2aamir
    New Member
    • Jul 2007
    • 2

    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 CreateRestauran ts < ActiveRecord::M igration
    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 RestaurantContr oller < ApplicationCont roller

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

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

    --restaurant.rhtm l
    <!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>Restaura nts: <%= controller.acti on_name %></title>
    <%= stylesheet_link _tag 'scaffold' %>
    <%= javascript_incl ude_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.733868932421 856;
    var centerLongitude = -84.479949474334 72;
    var startZoom = 16;
    var markerHash = {};
    var currentFocus = false;

    function addMarker(latit ude, longitude, id) {
    var marker = new GMarker(new GLatLng(latitud e, longitude));

    GEvent.addListe ner(marker, 'click',
    function() {
    //marker.openInfo WindowHtml(desc ription);
    focusPoint(id);
    });
    map.addOverlay( marker);
    return marker;
    }

    function init() {
    if (GBrowserIsComp atible()) {
    map = new GMap2(document. getElementById( "map"));
    map.addControl( new GSmallMapContro l());
    map.setCenter(n ew GLatLng(centerL atitude, centerLongitude ), startZoom);

    for (var i=0; i<markers.lengt h; i++) {
    //addMarker(resta urants[i].latitude, restaurants[i].longitude, restaurants[i].name);
    var current = markers[i];
    marker = addMarker(curre nt.latitude, current.longitu de, current.id);
    markerHash[current.id]={marker:marker , address:current .address, visible:true};
    }
    }
    }

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