1 class Tracepoint < ActiveRecord::Base
2 set_table_name 'gps_points'
4 validates_numericality_of :trackid, :only_integer => true
5 validates_numericality_of :latitude, :only_integer => true
6 validates_numericality_of :longitude, :only_integer => true
7 validates_associated :trace
8 validates_presence_of :timestamp
10 belongs_to :trace, :foreign_key => 'gpx_id'
12 before_save :update_tile
14 def self.find_by_area(minlat, minlon, maxlat, maxlon, options)
15 self.with_scope(:find => {:conditions => OSM.sql_for_area(minlat, minlon, maxlat, maxlon)}) do
16 return self.find(:all, options)
21 self.tile = QuadTile.tile_for_point(lat, lon)
25 self.latitude = (l * 10000000).round
29 self.longitude = (l * 10000000).round
33 return self.latitude.to_f / 10000000
37 return self.longitude.to_f / 10000000
41 el1 = XML::Node.new 'trkpt'
42 el1['lat'] = self.lat.to_s
43 el1['lon'] = self.lon.to_s