Created
July 20, 2010 03:56
-
-
Save hackervera/482493 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_distance | |
venues = [] | |
venues << Venue.new(:lat => 45.572952,:lon => -122.68394,:name => "my house", :vid => 6129841) | |
venues << Venue.new(:lat => 45.569133, :lon => -122.681568, :name => "new seasons", :vid => 42031) | |
venues << Venue.new(:lat => 45.429839, :lon => -122.574021, :name => "24 hour fitness clackamas", :vid => 115506) | |
venues << Venue.new(:vid => 89015, :name => "Fred Meyer, Arbor Lodge", :lat=> 45.577137, :lon => -122.68199) | |
venues << Venue.new(:vid => 39705, :name => "The Green Dragon", :lat => 45.515798, :lon => -122.656703) | |
venues << Venue.new(:vid => 36395, :name => "Oregon Convention Center", :lat => 45.528311, :lon => -122.663204) | |
doc = Nokogiri::XML(open("http://www.google.com/latitude/apps/badge/api?user=864060340584737485&type=atom#")) | |
lat,lon = doc.xpath("//georss:point").text.split(" ") | |
my_location = Geodesic::Position.new(lat.to_f,lon.to_f) | |
checkins = JSON.parse($r.get "checked_in") | |
venues.each { |venue| | |
d = Geodesic::dist_haversine(my_location.lat, my_location.lon, venue.lat, venue.lon) | |
puts "Distance to #{venue.name} is #{d} kilometers" | |
if d < 0.5 | |
puts "Distance less than .5 kilometers, checking into venue" | |
response = HTTParty.post("http://api.foursquare.com/v1/checkin", | |
:body => { "vid" => venue.vid, "shout" => "Checking in via Tyler's epic geofence app" }, | |
:basic_auth => { :username => "[email protected]", :password => "NOWAY" } ) | |
ap response | |
$r.set "fence:#{venue.name}", Time.now.to_i | |
return | |
end unless Time.now.to_i - $r.get("fence:#{venue.name}").to_i < 86400 | |
if Time.now.to_i - $r.get("fence:#{venue.name}").to_i < 86400 | |
puts "already checked in" | |
end | |
} | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment