Class: LocationFinderPage

Inherits:
Page
  • Object
show all
Includes:
GeoKit::Geocoders, Radiant::Taggable
Defined in:
app/models/location_finder_page.rb

Instance Method Summary collapse

Instance Method Details

#cache?Boolean

Returns:

  • (Boolean)

101
102
103
# File 'app/models/location_finder_page.rb', line 101

def cache?
  false
end

#process(request, response) ⇒ Object


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/models/location_finder_page.rb', line 50

def process(request,response)
  # Parameters
  # origin = Address string (if lat and lng are defined they are used preferentially)
  # lat = latitude of origin
  # lng = longitude of origin
  # distance = distance to search within
  # units = the units to apply to the distance (km or miles)
  # count = the number of results to return
  # offset = The result number to start with

  @origin   = request.parameters["origin"]
  @lat      = request.parameters["lat"]
  @lng      = request.parameters["lng"]
  @distance = request.parameters["distance"]
  @units    = request.parameters["units"]
  @count    = request.parameters["count"]
  @offset   = request.parameters["offset"]

  if @lat.blank? || @lng.blank?
    unless @origin.blank?
      geocode = MultiGeocoder.geocode(@origin)
      logger.debug("geocode: #{geocode}")
      @origin_geo = geocode if geocode.success
    else
      @origin_geo = nil;
    end
  else
    @origin_geo = [@lat.to_f, @lng.to_f]
  end

  @options = {}
  unless @origin_geo.nil?
    @options[:origin] = @origin_geo
    @options[:order] = "distance"
  end
  unless @distance.blank?
    @options[:within] = @distance
  end
  unless @units.blank?
    @options[:units] = @units
  end
  unless @count.blank?
    @options[:limit] = @count
  end
  unless @offset.blank?
    @options[:offset] = @offset
  end

  super request, response
end