Module: GTFS::Realtime::Nearby

Included in:
Stop, VehiclePosition
Defined in:
lib/gtfs/realtime/nearby.rb

Instance Method Summary collapse

Instance Method Details

#nearby(latitude, longitude) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/gtfs/realtime/nearby.rb', line 4

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 within the United States.

  all.select do |stop|
    (stop.latitude - latitude).abs < 0.01 &&
      (stop.longitude - longitude).abs < 0.01
  end
end