Permalink
Browse files

First working beta returning plain AR ids or fully fledged AR objects

for a nearby query. Awesome fast!
Signed-off-by: Jan Roesner <jan@roesner.it>
  • Loading branch information...
1 parent c17c0d8 commit 2bc825495edc289edd56b258f29b2c6f0f848830 @janroesner committed Mar 10, 2011
Showing with 13 additions and 10 deletions.
  1. +9 −8 lib/pin.rb
  2. +4 −2 lib/pin_caster.rb
View
@@ -25,11 +25,6 @@ def add_pin
Pincaster.add_record(self)
end
- # add a Pincaster record for self with layer: self.class BUT self's lng and lat are in RAD not DEG
- def add_pin_rad
- Pincaster.add_record_rad(self)
- end
-
# returns the Pincaster pin for self
def pin
Pincaster.get_record(self)
@@ -40,9 +35,15 @@ def delete_pin!
Pincaster.delete_record(self)
end
- # returns nearby Pincaster pins in given radius of self
- def nearby(radius)
- Pincaster.nearby(self, radius)
+ # returns nearby found record_ids in same layer as self, radius meters away, number of results limited to limit
+ def nearby_ids(radius, limit=nil)
+ pins = Pincaster.nearby(self, radius, limit)
+ JSON.parse(pins)["matches"].map{|p| p["key"]}
+ end
+
+ # returns nearby found records in same layer as self, radius metera away, number of results limited to limit
+ def nearby(radius, limit=nil)
+ self.class.find(nearby_ids(radius, limit))
end
# returns objects longitude depending on configured method name for access as well as DEG or RAD configuration
View
@@ -75,13 +75,15 @@ def self.delete_record(record)
@@http_client.send_request('DELETE', "/api/1.0/records/#{record.class.to_s}/#{record.id}.json").code == "200" ? true : false
end
- def self.nearby(record, radius, limit=200)
+ # returns all pins nearby given record, maximum radius meters away, returns limit number of pins
+ def self.nearby(record, radius, limit)
+ limit ||= 2000
raise "Given #{record.class.to_s} has not lng or lat." if record.pin_lng.nil? or record.pin_lat.nil?
@@http_client.send_request('GET',
"/api/1.0/search/#{record.class.to_s}/nearby/#{record.pin_lat.to_s},#{record.pin_lng.to_s}.json",
nil,
nil,
- {:radius => radius.to_s, :overflow => true})
+ {:radius => radius.to_s, :limit => limit}).body
end
end

0 comments on commit 2bc8254

Please sign in to comment.