class TZWhere::Query
Public Class Methods
new()
click to toggle source
# File lib/tzwhere/query.rb, line 3 def initialize @points ||= [] @timezones ||= [] load_points @kd = Kdtree.new(@points) end
Public Instance Methods
lookup(latitude, longitude)
click to toggle source
# File lib/tzwhere/query.rb, line 12 def lookup(latitude, longitude) @timezones.at(@kd.nearest(latitude, longitude)) end
Private Instance Methods
load_points()
click to toggle source
# File lib/tzwhere/query.rb, line 18 def load_points File.open(File.join(File.dirname(__FILE__) + "/points.dat"), "r").each_line do |line| lat, long, timezone = line.split @timezones.push(timezone) unless @timezones.index(timezone) @points << [lat.to_f, long.to_f, @timezones.index(timezone)] end end