def at(time)
      add_tracks if ! @tracks_added

      if time.is_a?(String)
        time = Time.parse(time)
      end
      time = time.to_i

      location = nil

      @tracks.each do |track|
        location = track.at(time)
        break if location
      end

      if ! location
        case @intersegment_behavior
        when :interpolate then
          @intersegments.each do |track|
            location = track.at(time)
            break if location
          end
        when :nearest then
          # hash is sorted in ascending time order.
          # all start/end points for all segments
          points = {}
          @tracks.each do |t|
            points[t.start_time.to_i] = t.start_location
            points[t.end_time.to_i] = t.end_location
          end

          last_diff = Infinity
          last_time = -1
          points.each do |p_time,p_location|
            this_diff = (p_time.to_i - time).abs

            # as long as the differences keep getting smaller, we keep going
            # as soon as we see a larger one, we step back one and use that value.
            if this_diff > last_diff
              l = points[last_time]
              location = Track.array_to_hash(points[last_time])
              break
            else
              last_diff = this_diff
              last_time = p_time
            end
          end

          # if we got here, time is > the end of the last segment
          location = Track.array_to_hash(points[last_time])
        end
      end

      # each segment has a begin and end time.
      # which one is this time closest to?
      # array of times in order. compute abs diff between time and each point.
      # put times in order. abs diff to each, until we get a larger value or we run out of points. then back up one and use that.
      # {time => [lat, lon, elev], time => [lat, lon, elev]}

      location
    end
def at(time)
      add_tracks if ! @tracks_added

      if time.is_a?(String)
        time = Time.parse(time)
      end
      time = time.to_i

      location = nil

      @tracks.each do |track|
        location = track.at(time)
        break if location
      end

      if ! location
        case @intersegment_behavior
        when :interpolate then
          @intersegments.each do |track|
            location = track.at(time)
            break if location
          end
        when :nearest then
          # hash is sorted in ascending time order.
          # all start/end points for all segments
          points = {}
          @tracks.each do |t|
            points[t.start_time.to_i] = t.start_location
            points[t.end_time.to_i] = t.end_location
          end

          last_diff = Infinity
          last_time = -1
          points.each do |p_time,p_location|
            this_diff = (p_time.to_i - time).abs

            # as long as the differences keep getting smaller, we keep going
            # as soon as we see a larger one, we step back one and use that value.
            if this_diff > last_diff
              l = points[last_time]
              location = Track.array_to_hash(points[last_time])
              break
            else
              last_diff = this_diff
              last_time = p_time
            end
          end

          # if we got here, time is > the end of the last segment
          location = Track.array_to_hash(points[last_time])
        end
      end

      # each segment has a begin and end time.
      # which one is this time closest to?
      # array of times in order. compute abs diff between time and each point.
      # put times in order. abs diff to each, until we get a larger value or we run out of points. then back up one and use that.
      # {time => [lat, lon, elev], time => [lat, lon, elev]}

      location
    end
infer a location from track data and a time

 @param [Time,String,Fixnum] time
 @return [Hash]
 @see Track#at