Sha256: f43f708af6014ad2185cc5a20939c84ab4a3ac92582df77f84b9d28ff4ac8b87
Contents?: true
Size: 779 Bytes
Versions: 2
Compression:
Stored size: 779 Bytes
Contents
module GTFS class Realtime module Nearby def self.included(base) base.send :include, InstanceMethods base.extend ClassMethods end module InstanceMethods def distance(latitude, longitude) Math::sqrt((latitude - self.latitude)**2 + (longitude - self.longitude)**2) end end module ClassMethods def nearby(latitude, longitude) # TODO: this math is terrible! It'll fail for various edge cases. # (e.g. close to the poles, overlapping to the prime meridian) # That said, it's an okay approximation away from the poles/meridian. all.select do |item| item.distance(latitude, longitude) < 0.01 end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
gtfs-realtime-0.4.0 | lib/gtfs/realtime/nearby.rb |
gtfs-realtime-0.3.0 | lib/gtfs/realtime/nearby.rb |