rails-geocoder 0.8.3 → 0.8.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +4 -0
- data/README.rdoc +9 -9
- data/VERSION +1 -1
- data/lib/geocoder.rb +26 -14
- data/rails-geocoder.gemspec +1 -1
- metadata +1 -1
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -44,22 +44,22 @@ If your model has +address+, +city+, +state+, and +country+ attributes your +loc
|
|
44
44
|
|
45
45
|
== 3. Use
|
46
46
|
|
47
|
-
Assuming +Venue+ is a geocoded model:
|
47
|
+
Assuming +Venue+ is a geocoded model, it has the following named scopes:
|
48
48
|
|
49
|
-
Venue.
|
50
|
-
Venue.
|
51
|
-
Venue.geocoded
|
52
|
-
Venue.not_geocoded
|
49
|
+
Venue.near('Omaha, NE, US', 20) # venues within 20 miles of Omaha
|
50
|
+
Venue.near([40.71, 100.23], 20) # venues within 20 miles of a point
|
51
|
+
Venue.geocoded # venues with coordinates
|
52
|
+
Venue.not_geocoded # venues without coordinates
|
53
53
|
|
54
54
|
Assuming +obj+ has a valid string for its +location+:
|
55
55
|
|
56
|
-
obj.fetch_coordinates
|
57
|
-
obj.fetch_coordinates!
|
56
|
+
obj.fetch_coordinates # returns coordinates [lat, lon]
|
57
|
+
obj.fetch_coordinates! # also writes coordinates to object
|
58
58
|
|
59
59
|
Assuming +obj+ is geocoded (has latitude and longitude):
|
60
60
|
|
61
|
-
obj.nearbys(30)
|
62
|
-
obj.distance_to(40.714, -100.234)
|
61
|
+
obj.nearbys(30) # other objects within 30 miles
|
62
|
+
obj.distance_to(40.714, -100.234) # distance to arbitrary point
|
63
63
|
|
64
64
|
Some utility methods are also available:
|
65
65
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.8.
|
1
|
+
0.8.4
|
data/lib/geocoder.rb
CHANGED
@@ -11,15 +11,30 @@ module Geocoder
|
|
11
11
|
base.class_eval do
|
12
12
|
|
13
13
|
# named scope: geocoded objects
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
named_scope :geocoded,
|
15
|
+
:conditions => "#{geocoder_options[:latitude]} IS NOT NULL " +
|
16
|
+
"AND #{geocoder_options[:longitude]} IS NOT NULL"
|
17
17
|
|
18
18
|
# named scope: not-geocoded objects
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
named_scope :not_geocoded,
|
20
|
+
:conditions => "#{geocoder_options[:latitude]} IS NULL " +
|
21
|
+
"OR #{geocoder_options[:longitude]} IS NULL"
|
22
|
+
|
23
|
+
##
|
24
|
+
# Find all objects within a radius (in miles) of the given location
|
25
|
+
# (address string). Location (the first argument) may be either a string
|
26
|
+
# to geocode or an array of coordinates (<tt>[lat,long]</tt>).
|
27
|
+
#
|
28
|
+
named_scope :near, lambda{ |location, *args|
|
29
|
+
latitude, longitude = location.is_a?(Array) ?
|
30
|
+
location : Geocoder.fetch_coordinates(location)
|
31
|
+
if latitude and longitude
|
32
|
+
find_near_options(latitude, longitude, *args)
|
33
|
+
else
|
34
|
+
{}
|
35
|
+
end
|
36
|
+
}
|
37
|
+
end
|
23
38
|
end
|
24
39
|
|
25
40
|
##
|
@@ -28,15 +43,12 @@ module Geocoder
|
|
28
43
|
module ClassMethods
|
29
44
|
|
30
45
|
##
|
31
|
-
#
|
32
|
-
# (address string). Location (the first argument) may be either a string
|
33
|
-
# to geocode or an array of coordinates (<tt>[lat,long]</tt>).
|
46
|
+
# DEPRECATED: Please use the +near+ method/named scope instead.
|
34
47
|
#
|
35
48
|
def find_near(location, radius = 20, options = {})
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
all(find_near_options(latitude, longitude, radius, options))
|
49
|
+
warn "Geocoder deprecation warning: the 'find_near' class method is " +
|
50
|
+
"deprecated, please use the 'near' method, which is a named scope."
|
51
|
+
near(location, radius, options)
|
40
52
|
end
|
41
53
|
|
42
54
|
##
|
data/rails-geocoder.gemspec
CHANGED