geokit-with-google-premier 1.5.0 → 1.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +45 -2
- data/lib/geokit/geocoders.rb +31 -0
- metadata +11 -4
data/README.markdown
CHANGED
@@ -1,8 +1,51 @@
|
|
1
1
|
## GEOKIT GEM DESCRIPTION
|
2
2
|
|
3
|
-
For Premier instructions visit
|
3
|
+
**For Premier instructions visit:**
|
4
|
+
|
5
|
+
1. http://groups.google.com/group/geokit/browse_thread/thread/14813f74bc0da41f/cd9d30f79dfa7088?lnk=gst&q=premier#cd9d30f79dfa7088
|
6
|
+
|
7
|
+
**Cache Support Added:**
|
8
|
+
credit: Brian Armstrong
|
9
|
+
http://groups.google.com/group/geokit/browse_thread/thread/cab2e140184de9bf/f29bc0d284b5cd41?lnk=gst&q=%5B%3Acache#f29bc0d284b5cd41
|
10
|
+
|
11
|
+
You need to:
|
12
|
+
|
13
|
+
1. Create GeocodeCache model
|
14
|
+
|
15
|
+
class CreateGeocodeCaches < ActiveRecord::Migration
|
16
|
+
def self.up
|
17
|
+
create_table :geocode_caches do |t|
|
18
|
+
t.string :address
|
19
|
+
t.float :lat
|
20
|
+
t.float :lng
|
21
|
+
|
22
|
+
t.timestamps
|
23
|
+
end
|
24
|
+
add_index :geocode_caches, :address
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.down
|
28
|
+
drop_table :geocode_caches
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
2. And then add a method to this model
|
34
|
+
|
35
|
+
class GeocodeCache < ActiveRecord::Base
|
36
|
+
def self.store address, lat, lng
|
37
|
+
GeocodeCache.create(:address=>address, :lat=>lat, :lng=>lng)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
3. In environment.rb add the new cache geocoder to the front of your priority list so it will try the cache first (note: this assumes you are using the MultiCoder)
|
42
|
+
|
43
|
+
GeoKit::Geocoders::provider_order = [:cache,:google,:yahoo]
|
44
|
+
|
45
|
+
4. To invalidate the cache occasionally you can run something like this in a cron job (addresses shouldn't move very often)
|
46
|
+
|
47
|
+
GeocodeCache.delete_all(["created_at < ?",2.months.ago]
|
4
48
|
|
5
|
-
http://groups.google.com/group/geokit/browse_thread/thread/14813f74bc0da41f/cd9d30f79dfa7088?lnk=gst&q=premier#cd9d30f79dfa7088
|
6
49
|
|
7
50
|
The Geokit gem provides:
|
8
51
|
|
data/lib/geokit/geocoders.rb
CHANGED
@@ -473,6 +473,11 @@ module Geokit
|
|
473
473
|
geoloc.all.push(extracted_geoloc)
|
474
474
|
end
|
475
475
|
end
|
476
|
+
|
477
|
+
## Cache the result
|
478
|
+
GeocodeCache.store(address, geoloc.lat, geoloc.lng)
|
479
|
+
logger.debug "Google geocoding CACHED. Address: #{address}. Place [#{geoloc.lat},#{geoloc.lng}]"
|
480
|
+
|
476
481
|
return geoloc
|
477
482
|
elsif doc.elements['//kml/Response/Status/code'].text == '620'
|
478
483
|
raise Geokit::TooManyQueriesError
|
@@ -602,6 +607,7 @@ module Geokit
|
|
602
607
|
res
|
603
608
|
end
|
604
609
|
end
|
610
|
+
|
605
611
|
|
606
612
|
# -------------------------------------------------------------------------------------------
|
607
613
|
# The Multi Geocoder
|
@@ -659,5 +665,30 @@ module Geokit
|
|
659
665
|
GeoLoc.new
|
660
666
|
end
|
661
667
|
end
|
668
|
+
|
669
|
+
# -------------------------------------------------------------------------------------------
|
670
|
+
# Caching
|
671
|
+
# -------------------------------------------------------------------------------------------
|
672
|
+
|
673
|
+
class CacheGeocoder < Geocoder
|
674
|
+
private
|
675
|
+
|
676
|
+
def self.do_geocode(address, options = {})
|
677
|
+
logger.error("TRYING CACHE")
|
678
|
+
|
679
|
+
cache = GeocodeCache.find(:first, :conditions => ["address = ?",address])
|
680
|
+
|
681
|
+
if cache.nil?
|
682
|
+
logger.debug "Cache result for #{address} was nil."
|
683
|
+
GeoLoc.new
|
684
|
+
else
|
685
|
+
res = GeoLoc.new(:lat=>cache.lat, :lng=>cache.lng)
|
686
|
+
res.success = true
|
687
|
+
logger.debug "GeoCode result from cache. Address: #{address}. Place [#{cache.lat},#{cache.lng}]"
|
688
|
+
res
|
689
|
+
end
|
690
|
+
end
|
691
|
+
end
|
692
|
+
|
662
693
|
end
|
663
694
|
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geokit-with-google-premier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 5
|
8
|
+
- 5
|
9
|
+
version: 1.5.5
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Andre Lewis and Bill Eisenhauer
|
@@ -53,18 +58,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
53
58
|
requirements:
|
54
59
|
- - ">="
|
55
60
|
- !ruby/object:Gem::Version
|
61
|
+
segments:
|
62
|
+
- 0
|
56
63
|
version: "0"
|
57
|
-
version:
|
58
64
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
65
|
requirements:
|
60
66
|
- - ">="
|
61
67
|
- !ruby/object:Gem::Version
|
68
|
+
segments:
|
69
|
+
- 0
|
62
70
|
version: "0"
|
63
|
-
version:
|
64
71
|
requirements: []
|
65
72
|
|
66
73
|
rubyforge_project: geokit
|
67
|
-
rubygems_version: 1.3.
|
74
|
+
rubygems_version: 1.3.6
|
68
75
|
signing_key:
|
69
76
|
specification_version: 2
|
70
77
|
summary: none
|