soey-geokit 1.2.4
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/Manifest.txt +19 -0
- data/README.markdown +166 -0
- data/Rakefile +20 -0
- data/lib/geokit/geocoders.rb +549 -0
- data/lib/geokit/mappable.rb +459 -0
- data/lib/geokit.rb +28 -0
- data/test/test_base_geocoder.rb +56 -0
- data/test/test_bounds.rb +74 -0
- data/test/test_ca_geocoder.rb +41 -0
- data/test/test_geoloc.rb +49 -0
- data/test/test_google_geocoder.rb +88 -0
- data/test/test_latlng.rb +132 -0
- data/test/test_multi_geocoder.rb +44 -0
- data/test/test_us_geocoder.rb +47 -0
- data/test/test_yahoo_geocoder.rb +87 -0
- metadata +78 -0
data/Manifest.txt
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
.project
|
2
|
+
Manifest.txt
|
3
|
+
README.markdown
|
4
|
+
Rakefile
|
5
|
+
geokit.gemspec
|
6
|
+
lib/geokit.rb
|
7
|
+
lib/geokit/geocoders.rb
|
8
|
+
lib/geokit/mappable.rb
|
9
|
+
test/test_base_geocoder.rb
|
10
|
+
test/test_bounds.rb
|
11
|
+
test/test_ca_geocoder.rb
|
12
|
+
test/test_geoloc.rb
|
13
|
+
test/test_google_geocoder.rb
|
14
|
+
test/test_google_reverse_geocoder.rb
|
15
|
+
test/test_ipgeocoder.rb
|
16
|
+
test/test_latlng.rb
|
17
|
+
test/test_multi_geocoder.rb
|
18
|
+
test/test_us_geocoder.rb
|
19
|
+
test/test_yahoo_geocoder.rb
|
data/README.markdown
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
## GEOKIT GEM DESCRIPTION
|
2
|
+
|
3
|
+
The Geokit gem provides:
|
4
|
+
|
5
|
+
* Distance calculations between two points on the earth. Calculate the distance in miles, kilometers, or nautical miles, with all the trigonometry abstracted away by GeoKit.
|
6
|
+
* Geocoding from multiple providers. It supports Google, Yahoo, Geocoder.us, and Geocoder.ca geocoders, and others. It provides a uniform response structure from all of them.
|
7
|
+
It also provides a fail-over mechanism, in case your input fails to geocode in one service.
|
8
|
+
* Rectangular bounds calculations: is a point within a given rectangular bounds?
|
9
|
+
* Heading and midpoint calculations
|
10
|
+
|
11
|
+
Combine this with gem with the [geokit-rails plugin](http://github.com/andre/geokit-rails/tree/master) to get location-based finders for your Rails app.
|
12
|
+
|
13
|
+
* Geokit Documentation at Rubyforge [http://geokit.rubyforge.org](http://geokit.rubyforge.org).
|
14
|
+
* Repository at Github: [http://github.com/andre/geokit-gem/tree/master](http://github.com/andre/geokit-gem/tree/master).
|
15
|
+
|
16
|
+
## INSTALL
|
17
|
+
|
18
|
+
gem sources -a http://gems.github.com
|
19
|
+
sudo gem install andre-geokit
|
20
|
+
|
21
|
+
## QUICK START
|
22
|
+
|
23
|
+
irb> require 'rubygems'
|
24
|
+
irb> require 'geokit'
|
25
|
+
irb> a=Geokit::Geocoders::YahooGeocoder.geocode '140 Market St, San Francisco, CA'
|
26
|
+
irb> a.ll
|
27
|
+
=> 37.79363,-122.396116
|
28
|
+
irb> b=Geokit::Geocoders::YahooGeocoder.geocode '789 Geary St, San Francisco, CA'
|
29
|
+
irb> b.ll
|
30
|
+
=> 37.786217,-122.41619
|
31
|
+
irb> a.distance_to(b)
|
32
|
+
=> 1.21120007413626
|
33
|
+
irb> a.heading_to(b)
|
34
|
+
=> 244.959832435678
|
35
|
+
irb(main):006:0> c=a.midpoint_to(b) # what's halfway from a to b?
|
36
|
+
irb> c.ll
|
37
|
+
=> "37.7899239257175,-122.406153503469"
|
38
|
+
irb(main):008:0> d=c.endpoint(90,10) # what's 10 miles to the east of c?
|
39
|
+
irb> d.ll
|
40
|
+
=> "37.7897825005142,-122.223214776155"
|
41
|
+
|
42
|
+
FYI, that `.ll` method means "latitude longitude".
|
43
|
+
|
44
|
+
See the RDOC more more ... there are also operations on rectangular bounds (e.g., determining if a point is within bounds, find the center, etc).
|
45
|
+
|
46
|
+
## CONFIGURATION
|
47
|
+
|
48
|
+
If you're using this gem by itself, here's how to set configurations:
|
49
|
+
|
50
|
+
# These defaults are used in Geokit::Mappable.distance_to and in acts_as_mappable
|
51
|
+
Geokit::default_units = :miles
|
52
|
+
Geokit::default_formula = :sphere
|
53
|
+
|
54
|
+
# This is the timeout value in seconds to be used for calls to the geocoder web
|
55
|
+
# services. For no timeout at all, comment out the setting. The timeout unit
|
56
|
+
# is in seconds.
|
57
|
+
Geokit::Geocoders::timeout = 3
|
58
|
+
|
59
|
+
# These settings are used if web service calls must be routed through a proxy.
|
60
|
+
# These setting can be nil if not needed, otherwise, addr and port must be
|
61
|
+
# filled in at a minimum. If the proxy requires authentication, the username
|
62
|
+
# and password can be provided as well.
|
63
|
+
Geokit::Geocoders::proxy_addr = nil
|
64
|
+
Geokit::Geocoders::proxy_port = nil
|
65
|
+
Geokit::Geocoders::proxy_user = nil
|
66
|
+
Geokit::Geocoders::proxy_pass = nil
|
67
|
+
|
68
|
+
# This is your yahoo application key for the Yahoo Geocoder.
|
69
|
+
# See http://developer.yahoo.com/faq/index.html#appid
|
70
|
+
# and http://developer.yahoo.com/maps/rest/V1/geocode.html
|
71
|
+
Geokit::Geocoders::yahoo = 'REPLACE_WITH_YOUR_YAHOO_KEY'
|
72
|
+
|
73
|
+
# This is your Google Maps geocoder key.
|
74
|
+
# See http://www.google.com/apis/maps/signup.html
|
75
|
+
# and http://www.google.com/apis/maps/documentation/#Geocoding_Examples
|
76
|
+
Geokit::Geocoders::google = 'REPLACE_WITH_YOUR_GOOGLE_KEY'
|
77
|
+
|
78
|
+
# This is your username and password for geocoder.us.
|
79
|
+
# To use the free service, the value can be set to nil or false. For
|
80
|
+
# usage tied to an account, the value should be set to username:password.
|
81
|
+
# See http://geocoder.us
|
82
|
+
# and http://geocoder.us/user/signup
|
83
|
+
Geokit::Geocoders::geocoder_us = false
|
84
|
+
|
85
|
+
# This is your authorization key for geocoder.ca.
|
86
|
+
# To use the free service, the value can be set to nil or false. For
|
87
|
+
# usage tied to an account, set the value to the key obtained from
|
88
|
+
# Geocoder.ca.
|
89
|
+
# See http://geocoder.ca
|
90
|
+
# and http://geocoder.ca/?register=1
|
91
|
+
Geokit::Geocoders::geocoder_ca = false
|
92
|
+
|
93
|
+
# This is the order in which the geocoders are called in a failover scenario
|
94
|
+
# If you only want to use a single geocoder, put a single symbol in the array.
|
95
|
+
# Valid symbols are :google, :yahoo, :us, and :ca.
|
96
|
+
# Be aware that there are Terms of Use restrictions on how you can use the
|
97
|
+
# various geocoders. Make sure you read up on relevant Terms of Use for each
|
98
|
+
# geocoder you are going to use.
|
99
|
+
Geokit::Geocoders::provider_order = [:google,:us]
|
100
|
+
|
101
|
+
If you're using this gem with the [geokit-rails plugin](http://github.com/andre/geokit-rails/tree/master), the plugin
|
102
|
+
creates a template with these settings and places it in `config/initializers/geokit_config.rb`.
|
103
|
+
|
104
|
+
## SUPPORTED GEOCODERS
|
105
|
+
|
106
|
+
### "regular" address geocoders
|
107
|
+
* Yahoo Geocoder - requires an API key.
|
108
|
+
* Geocoder.us - may require authentication if performing more than the free request limit.
|
109
|
+
* Geocoder.ca - for Canada; may require authentication as well.
|
110
|
+
* Geonames - a free geocoder
|
111
|
+
|
112
|
+
### address geocoders that also provide reverse geocoding
|
113
|
+
* Google Geocoder - requires an API key.
|
114
|
+
|
115
|
+
### IP address geocoders
|
116
|
+
* IP Geocoder - geocodes an IP address using hostip.info's web service.
|
117
|
+
* Geoplugin.net -- another IP address geocoder
|
118
|
+
|
119
|
+
### The Multigeocoder
|
120
|
+
* Multi Geocoder - provides failover for the physical location geocoders.
|
121
|
+
|
122
|
+
## NOTES ON WHAT'S WHERE
|
123
|
+
|
124
|
+
mappable.rb contains the Mappable module, which provides basic
|
125
|
+
distance calculation methods, i.e., calculating the distance
|
126
|
+
between two points.
|
127
|
+
|
128
|
+
mappable.rb also contains LatLng, GeoLoc, and Bounds.
|
129
|
+
LatLng is a simple container for latitude and longitude, but
|
130
|
+
it's made more powerful by mixing in the above-mentioned Mappable
|
131
|
+
module -- therefore, you can calculate easily the distance between two
|
132
|
+
LatLng ojbects with `distance = first.distance_to(other)`
|
133
|
+
|
134
|
+
GeoLoc (also in mappable.rb) represents an address or location which
|
135
|
+
has been geocoded. You can get the city, zipcode, street address, etc.
|
136
|
+
from a GeoLoc object. GeoLoc extends LatLng, so you also get lat/lng
|
137
|
+
AND the Mappable modeule goodness for free.
|
138
|
+
|
139
|
+
geocoders.rb contains all the geocoder implemenations. All the gercoders
|
140
|
+
inherit from a common base (class Geocoder) and implement the private method
|
141
|
+
do_geocode.
|
142
|
+
|
143
|
+
## LICENSE
|
144
|
+
|
145
|
+
(The MIT License)
|
146
|
+
|
147
|
+
Copyright (c) 2007-2009 Andre Lewis and Bill Eisenhauer
|
148
|
+
|
149
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
150
|
+
a copy of this software and associated documentation files (the
|
151
|
+
'Software'), to deal in the Software without restriction, including
|
152
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
153
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
154
|
+
permit persons to whom the Software is furnished to do so, subject to
|
155
|
+
the following conditions:
|
156
|
+
|
157
|
+
The above copyright notice and this permission notice shall be
|
158
|
+
included in all copies or substantial portions of the Software.
|
159
|
+
|
160
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
161
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
162
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
163
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
164
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
165
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
166
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/geokit'
|
6
|
+
|
7
|
+
Hoe.new('Geokit', Geokit::VERSION) do |p|
|
8
|
+
# p.rubyforge_name = 'Geokitx' # if different than lowercase project name
|
9
|
+
p.developer('Andre Lewis and Bill Eisenhauer', 'andre@earthcode.com / bill_eisenhauer@yahoo.com')
|
10
|
+
end
|
11
|
+
|
12
|
+
task :generate_gemspec do
|
13
|
+
system "rake debug_gem | grep -v \"(in \" > `basename \\`pwd\\``.gemspec"
|
14
|
+
end
|
15
|
+
|
16
|
+
task :update_manifest do
|
17
|
+
system "touch Manifest.txt; rake check_manifest | grep -v \"(in \" | patch"
|
18
|
+
end
|
19
|
+
|
20
|
+
# vim: syntax=Ruby
|