473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Google map and scaffolding

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.

Expand|Select|Wrap|Line Numbers
  1. class CreateRestaurants < ActiveRecord::Migration
  2.   def self.up
  3.     create_table :restaurants do |t|
  4.       t.column :category, :string
  5.       t.column :name, :string
  6.       t.column :address, :string
  7.       t.column :phone, :string
  8.       t.column :hours, :text
  9.       t.column :more_info, :text
  10.       t.column :latitude, :float
  11.       t.column :longitude, :float
  12.     end
  13.   end
  14.  
  15.   def self.down
  16.     drop_table :restaurants
  17.   end
  18. end
  19.  
  20. class RestaurantController < ApplicationController
  21.  
  22.   def map
  23.     @restaurants = Restaurant.find :all
  24.   end
  25. end
  26.  
  27. --index.rhtml--
  28. <div id="map" style="width: 500px; height: 300px"></div>
  29.  
  30. --restaurant.rhtml
  31. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  32.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  33. <html xmlns="http://www.w3.org/1999/xhtml">
  34. <head>
  35.   <title>Restaurants: <%= controller.action_name %></title>
  36.   <%= stylesheet_link_tag 'scaffold' %>
  37.   <%= javascript_include_tag 'map' %>
  38.   <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=KEY"
  39.   type="text/javascript"></script>
  40. <script type="text/javascript">var restaurants=<%= @restaurants.to_json %>;</script>
  41. </head>
  42.  
  43. <body>
  44. <p style="color: green"><%= flash[:notice] %></p>
  45.  
  46. <%= yield  %>
  47.  
  48. </body>
  49. </html>
  50.  
  51. --map.js--
  52. var map;
  53. var centerLatitude = 42.733868932421856;
  54. var centerLongitude = -84.47994947433472;
  55. var startZoom = 16;
  56. var markerHash = {};
  57. var currentFocus = false;
  58.  
  59. function addMarker(latitude, longitude, id) {
  60.     var marker = new GMarker(new GLatLng(latitude, longitude));
  61.  
  62.     GEvent.addListener(marker, 'click',
  63.     function() {
  64.         //marker.openInfoWindowHtml(description);
  65.         focusPoint(id);
  66.     });
  67.     map.addOverlay(marker);
  68.     return marker;
  69. }
  70.  
  71. function init() {
  72.     if (GBrowserIsCompatible()) {
  73.         map = new GMap2(document.getElementById("map"));
  74.         map.addControl(new GSmallMapControl());
  75.         map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);
  76.  
  77.         for (var i=0; i<markers.length; i++) {
  78.             //addMarker(restaurants[i].latitude, restaurants[i].longitude, restaurants[i].name);
  79.             var current = markers[i];
  80.             marker = addMarker(current.latitude, current.longitude, current.id);
  81.             markerHash[current.id]={marker:marker, address:current.address, visible:true};
  82.         }
  83.     }
  84. }
  85.  
  86. window.onload = init;
  87. window.onunload = GUnload;
  88.  
Apr 5 '07 #1
1 3819
DID U GET THE CORRECT CODE FOR THIS ONE?

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.
Jul 19 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: fuzzyman | last post by:
I've hacked together a 'GoogleCacheServer'. It is based on SimpleHTTPServer. Run the following script (hopefully google groups won't mangle the indentation) and set your browser proxy settings to...
0
by: Michael Tobis | last post by:
An article of mine, entitled "PyNSol: Objects as Scaffolding" has appeared in Computing in Science and Engineering. You can read it at http://www.computer.org/portal/site/cise/ or...
3
by: Alastair | last post by:
Hello guys, I've been building a search facility for an intranet site I'm part of developing and we've been building a search engine using Index Server. It mostly works, however there have been...
2
by: gen_tricomi | last post by:
THE IMPORTANCE OF MAKING THE GOOGLE INDEX DOWNLOADABLE I write here to make a request on behalf of all the programmers on earth who have been or are intending to use the Google web search API...
1
by: xahlee | last post by:
Elisp Tutorial: Make Google Earth Xah Lee, 2006-12 This page shows a example of writing a emacs lisp function that creates a Google Earth file, and creates a link to the file, as well a link...
2
by: Armando Padilla | last post by:
Hi everyone just wanted to put this out there and see what you all thought. i created a simple scaffolding script for php that creates the CRUD methods and the classes for each table in your DB. ...
11
by: Faisal Vali | last post by:
Are there any guidelines people use that help them decide when it is better to dynamically generate all html elements using javascript versus actually writing some html and using it as scaffolding?...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.