Permalink
Browse files

add controller that generate layar docs

  • Loading branch information...
1 parent aff61dc commit bbd3d98295e2bd6f434d1741a4204022756cc488 @siuying committed Sep 11, 2009
Showing with 5,268 additions and 2 deletions.
  1. +34 −0 app/controllers/geo_controller.rb
  2. +2 −0 app/helpers/geo_helper.rb
  3. +24 −0 app/models/point.rb
  4. +2 −2 config/environment.rb
  5. +61 −0 config/initializers/geokit_config.rb
  6. +1 −0 db/loc.js
  7. +24 −0 db/migrate/20090911151640_create_points.rb
  8. +28 −0 db/schema.rb
  9. +15 −0 script/import
  10. +15 −0 test/fixtures/points.yml
  11. +8 −0 test/functional/geo_controller_test.rb
  12. +4 −0 test/unit/helpers/geo_helper_test.rb
  13. +8 −0 test/unit/point_test.rb
  14. +101 −0 vendor/gems/geokit-1.4.1/.specification
  15. +71 −0 vendor/gems/geokit-1.4.1/History.txt
  16. +21 −0 vendor/gems/geokit-1.4.1/Manifest.txt
  17. +273 −0 vendor/gems/geokit-1.4.1/README.markdown
  18. +22 −0 vendor/gems/geokit-1.4.1/Rakefile
  19. +32 −0 vendor/gems/geokit-1.4.1/geokit.gemspec
  20. +30 −0 vendor/gems/geokit-1.4.1/lib/geokit.rb
  21. +644 −0 vendor/gems/geokit-1.4.1/lib/geokit/geocoders.rb
  22. +527 −0 vendor/gems/geokit-1.4.1/lib/geokit/mappable.rb
  23. +58 −0 vendor/gems/geokit-1.4.1/test/test_base_geocoder.rb
  24. +97 −0 vendor/gems/geokit-1.4.1/test/test_bounds.rb
  25. +41 −0 vendor/gems/geokit-1.4.1/test/test_ca_geocoder.rb
  26. +72 −0 vendor/gems/geokit-1.4.1/test/test_geoloc.rb
  27. +59 −0 vendor/gems/geokit-1.4.1/test/test_geoplugin_geocoder.rb
  28. +183 −0 vendor/gems/geokit-1.4.1/test/test_google_geocoder.rb
  29. +49 −0 vendor/gems/geokit-1.4.1/test/test_google_reverse_geocoder.rb
  30. +24 −0 vendor/gems/geokit-1.4.1/test/test_inflector.rb
  31. +88 −0 vendor/gems/geokit-1.4.1/test/test_ipgeocoder.rb
  32. +209 −0 vendor/gems/geokit-1.4.1/test/test_latlng.rb
  33. +93 −0 vendor/gems/geokit-1.4.1/test/test_multi_geocoder.rb
  34. +38 −0 vendor/gems/geokit-1.4.1/test/test_multi_ip_geocoder.rb
  35. +56 −0 vendor/gems/geokit-1.4.1/test/test_us_geocoder.rb
  36. +105 −0 vendor/gems/geokit-1.4.1/test/test_yahoo_geocoder.rb
  37. +35 −0 vendor/plugins/geokit-rails/CHANGELOG.rdoc
  38. +20 −0 vendor/plugins/geokit-rails/MIT-LICENSE
  39. +541 −0 vendor/plugins/geokit-rails/README.markdown
  40. +23 −0 vendor/plugins/geokit-rails/Rakefile
  41. +9 −0 vendor/plugins/geokit-rails/about.yml
  42. +61 −0 vendor/plugins/geokit-rails/assets/api_keys_template
  43. +1 −0 vendor/plugins/geokit-rails/init.rb
  44. +14 −0 vendor/plugins/geokit-rails/install.rb
  45. +25 −0 vendor/plugins/geokit-rails/lib/geokit-rails.rb
  46. +467 −0 vendor/plugins/geokit-rails/lib/geokit-rails/acts_as_mappable.rb
  47. +22 −0 vendor/plugins/geokit-rails/lib/geokit-rails/defaults.rb
  48. +16 −0 vendor/plugins/geokit-rails/lib/geokit-rails/geocoder_control.rb
  49. +46 −0 vendor/plugins/geokit-rails/lib/geokit-rails/ip_geocode_lookup.rb
  50. +537 −0 vendor/plugins/geokit-rails/test/acts_as_mappable_test.rb
  51. +12 −0 vendor/plugins/geokit-rails/test/database.yml
  52. +7 −0 vendor/plugins/geokit-rails/test/fixtures/companies.yml
  53. +54 −0 vendor/plugins/geokit-rails/test/fixtures/custom_locations.yml
  54. +54 −0 vendor/plugins/geokit-rails/test/fixtures/locations.yml
  55. +17 −0 vendor/plugins/geokit-rails/test/fixtures/mock_addresses.yml
  56. +2 −0 vendor/plugins/geokit-rails/test/fixtures/mock_families.yml
  57. +9 −0 vendor/plugins/geokit-rails/test/fixtures/mock_houses.yml
  58. +5 −0 vendor/plugins/geokit-rails/test/fixtures/mock_organizations.yml
  59. +5 −0 vendor/plugins/geokit-rails/test/fixtures/mock_people.yml
  60. 0 vendor/plugins/geokit-rails/test/fixtures/stores.yml
  61. +84 −0 vendor/plugins/geokit-rails/test/ip_geocode_lookup_test.rb
  62. +60 −0 vendor/plugins/geokit-rails/test/schema.rb
  63. +23 −0 vendor/plugins/geokit-rails/test/test_helper.rb
@@ -0,0 +1,34 @@
+require 'digest/sha1'
+require 'geokit'
+
+class GeoController < ApplicationController
+
+ def index
+ userId = params[:userId]
+ developerId = params[:developerId]
+ developerHash = params[:developerHash]
+ timestamp = params[:timestamp]
+ layerName = params[:layerName]
+ lat = params[:lat].to_f
+ lng = params[:lon].to_f
+ radius = (params[:radius] || "2500").to_f / 1000.0
+
+ # developerHashCorrect = Digest::SHA1.hexdigest(developerId + timestamp)
+ # if developerHash != developerHashCorrect
+ # render :text => "no permission", :status => 403
+ # return
+ # end
+
+ current = Geokit::LatLng.new(lat, lng)
+ points = Point.find(:all, :origin =>[lat, lng], :within => radius, :conditions=>{ :group => layerName })
+
+ hotspots = points.collect() do |p|
+ poi = p.to_poi
+ poi[:distance] = p.distance_to(current)
+ poi
+ end
+
+ result = {:layer => layerName, :errorCode => "0", :errorString => "ok", :hotspots => hotspots}
+ result.to_json
+ end
+end
@@ -0,0 +1,2 @@
+module GeoHelper
+end
View
@@ -0,0 +1,24 @@
+class Point < ActiveRecord::Base
+ acts_as_mappable :auto_geocode => true,
+ :default_units => :kms,
+ :default_formula => :sphere,
+ :distance_field_name => :distance,
+ :lat_column_name => :lat,
+ :lng_column_name => :lng
+
+ def to_poi(current_point)
+ {
+ :actions => [],
+ :attribution => "www.mcdonald.com.hk",
+ :id => id,
+ :imageURL => nil,
+ :lat => lat,
+ :lon => lng,
+ :title => name,
+ :line2 => address,
+ :line3 => phone,
+ :line4 => "",
+ :type => 0
+ }
+ end
+end
View
@@ -15,9 +15,9 @@
# config.load_paths += %W( #{RAILS_ROOT}/extras )
# Specify gems that this application depends on and have them installed with rake gems:install
- # config.gem "bj"
+ config.gem "geokit"
+
# config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
- # config.gem "sqlite3-ruby", :lib => "sqlite3"
# config.gem "aws-s3", :lib => "aws/s3"
# Only load the plugins named here, in the order given (default is alphabetical).
@@ -0,0 +1,61 @@
+if defined? Geokit
+
+ # These defaults are used in Geokit::Mappable.distance_to and in acts_as_mappable
+ Geokit::default_units = :miles
+ Geokit::default_formula = :sphere
+
+ # This is the timeout value in seconds to be used for calls to the geocoder web
+ # services. For no timeout at all, comment out the setting. The timeout unit
+ # is in seconds.
+ Geokit::Geocoders::timeout = 3
+
+ # These settings are used if web service calls must be routed through a proxy.
+ # These setting can be nil if not needed, otherwise, addr and port must be
+ # filled in at a minimum. If the proxy requires authentication, the username
+ # and password can be provided as well.
+ Geokit::Geocoders::proxy_addr = nil
+ Geokit::Geocoders::proxy_port = nil
+ Geokit::Geocoders::proxy_user = nil
+ Geokit::Geocoders::proxy_pass = nil
+
+ # This is your yahoo application key for the Yahoo Geocoder.
+ # See http://developer.yahoo.com/faq/index.html#appid
+ # and http://developer.yahoo.com/maps/rest/V1/geocode.html
+ # Geokit::Geocoders::yahoo = 'REPLACE_WITH_YOUR_YAHOO_KEY'
+
+ # This is your Google Maps geocoder key.
+ # See http://www.google.com/apis/maps/signup.html
+ # and http://www.google.com/apis/maps/documentation/#Geocoding_Examples
+ Geokit::Geocoders::google = 'ABQIAAAAHkXTEjC7ErFpCj-xqqWd0hRxiwgtZmcKZZrn-dAmkO3QPxlMoBSMLmoE9KonndGc98YVFV3hqYlnvg'
+
+ # This is your username and password for geocoder.us.
+ # To use the free service, the value can be set to nil or false. For
+ # usage tied to an account, the value should be set to username:password.
+ # See http://geocoder.us
+ # and http://geocoder.us/user/signup
+ Geokit::Geocoders::geocoder_us = false
+
+ # This is your authorization key for geocoder.ca.
+ # To use the free service, the value can be set to nil or false. For
+ # usage tied to an account, set the value to the key obtained from
+ # Geocoder.ca.
+ # See http://geocoder.ca
+ # and http://geocoder.ca/?register=1
+ Geokit::Geocoders::geocoder_ca = false
+
+ # Uncomment to use a username with the Geonames geocoder
+ #Geokit::Geocoders::geonames="REPLACE_WITH_YOUR_GEONAMES_USERNAME"
+
+ # This is the order in which the geocoders are called in a failover scenario
+ # If you only want to use a single geocoder, put a single symbol in the array.
+ # Valid symbols are :google, :yahoo, :us, and :ca.
+ # Be aware that there are Terms of Use restrictions on how you can use the
+ # various geocoders. Make sure you read up on relevant Terms of Use for each
+ # geocoder you are going to use.
+ Geokit::Geocoders::provider_order = [:google,:us]
+
+ # The IP provider order. Valid symbols are :ip,:geo_plugin.
+ # As before, make sure you read up on relevant Terms of Use for each
+ # Geokit::Geocoders::ip_provider_order = [:geo_plugin,:ip]
+
+end
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,24 @@
+class CreatePoints < ActiveRecord::Migration
+ def self.up
+ create_table :points do |t|
+ t.string "group"
+ t.string "name"
+ t.string "address"
+ t.string "phone"
+ t.string "state"
+ t.decimal "lat"
+ t.decimal "lng"
+
+ t.datetime "created_at"
+ t.datetime "updated_at"
+
+ t.timestamps
+ end
+
+ add_index :points, :group
+ end
+
+ def self.down
+ drop_table :points
+ end
+end
View
@@ -0,0 +1,28 @@
+# This file is auto-generated from the current state of the database. Instead of editing this file,
+# please use the migrations feature of Active Record to incrementally modify your database, and
+# then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your database schema. If you need
+# to create the application database on another system, you should be using db:schema:load, not running
+# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended to check this file into your version control system.
+
+ActiveRecord::Schema.define(:version => 20090911151640) do
+
+ create_table "points", :force => true do |t|
+ t.string "group"
+ t.string "name"
+ t.string "address"
+ t.string "phone"
+ t.string "state"
+ t.decimal "lat"
+ t.decimal "lng"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ add_index "points", ["group"], :name => "index_points_on_group"
+
+end
View
@@ -0,0 +1,15 @@
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require 'json'
+
+dataset = JSON.parse(open('db/loc.js').read)
+dataset.each do |data|
+ name = data[0]
+ addr = data[1]
+ phone = data[2]
+
+ p = Point.create(:name => name, :address => addr, :phone => phone)
+ puts "point created: #{p.name} #{p.address}"
+ sleep(0.5)
+end
View
@@ -0,0 +1,15 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+one:
+ string:
+ string:
+ string:
+ string:
+ string:
+
+two:
+ string:
+ string:
+ string:
+ string:
+ string:
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class GeoControllerTest < ActionController::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class GeoHelperTest < ActionView::TestCase
+end
View
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class PointTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
@@ -0,0 +1,101 @@
+--- !ruby/object:Gem::Specification
+name: geokit
+version: !ruby/object:Gem::Version
+ version: 1.4.1
+platform: ruby
+authors:
+- Andre Lewis
+autorequire:
+bindir: bin
+cert_chain: []
+
+date: 2009-06-15 00:00:00 +08:00
+default_executable:
+dependencies:
+- !ruby/object:Gem::Dependency
+ name: hoe
+ type: :development
+ version_requirement:
+ version_requirements: !ruby/object:Gem::Requirement
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ version: 1.12.2
+ version:
+description: ""
+email:
+- andre@earthcode.com
+executables: []
+
+extensions: []
+
+extra_rdoc_files:
+- History.txt
+- Manifest.txt
+files:
+- History.txt
+- Manifest.txt
+- README.markdown
+- Rakefile
+- geokit.gemspec
+- lib/geokit.rb
+- lib/geokit/geocoders.rb
+- lib/geokit/mappable.rb
+- test/test_base_geocoder.rb
+- test/test_bounds.rb
+- test/test_ca_geocoder.rb
+- test/test_geoloc.rb
+- test/test_geoplugin_geocoder.rb
+- test/test_google_geocoder.rb
+- test/test_google_reverse_geocoder.rb
+- test/test_inflector.rb
+- test/test_ipgeocoder.rb
+- test/test_latlng.rb
+- test/test_multi_geocoder.rb
+- test/test_us_geocoder.rb
+- test/test_yahoo_geocoder.rb
+- test/test_multi_ip_geocoder.rb
+has_rdoc: true
+homepage:
+licenses: []
+
+post_install_message:
+rdoc_options:
+- --main
+- README.txt
+require_paths:
+- lib
+required_ruby_version: !ruby/object:Gem::Requirement
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ version: "0"
+ version:
+required_rubygems_version: !ruby/object:Gem::Requirement
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ version: "0"
+ version:
+requirements: []
+
+rubyforge_project: geokit
+rubygems_version: 1.3.5
+signing_key:
+specification_version: 3
+summary: Geokit provides geocoding and distance calculation in an easy-to-use API
+test_files:
+- test/test_base_geocoder.rb
+- test/test_bounds.rb
+- test/test_ca_geocoder.rb
+- test/test_geoloc.rb
+- test/test_geoplugin_geocoder.rb
+- test/test_google_geocoder.rb
+- test/test_google_reverse_geocoder.rb
+- test/test_inflector.rb
+- test/test_ipgeocoder.rb
+- test/test_latlng.rb
+- test/test_multi_geocoder.rb
+- test/test_multi_ip_geocoder.rb
+- test/test_us_geocoder.rb
+- test/test_yahoo_geocoder.rb
Oops, something went wrong.

0 comments on commit bbd3d98

Please sign in to comment.