- return "south-west" if bearing >= 22.5 and bearing < 67.5
- return "south" if bearing >= 67.5 and bearing < 112.5
- return "south-east" if bearing >= 112.5 and bearing < 157.5
- return "east" if bearing >= 157.5 and bearing < 202.5
- return "north-east" if bearing >= 202.5 and bearing < 247.5
- return "north" if bearing >= 247.5 and bearing < 292.5
- return "north-west" if bearing >= 292.5 and bearing < 337.5
- return "west"
+ return t("geocoder.direction.south_west") if bearing >= 22.5 and bearing < 67.5
+ return t("geocoder.direction.south") if bearing >= 67.5 and bearing < 112.5
+ return t("geocoder.direction.south_east") if bearing >= 112.5 and bearing < 157.5
+ return t("geocoder.direction.east") if bearing >= 157.5 and bearing < 202.5
+ return t("geocoder.direction.north_east") if bearing >= 202.5 and bearing < 247.5
+ return t("geocoder.direction.north") if bearing >= 247.5 and bearing < 292.5
+ return t("geocoder.direction.north_west") if bearing >= 292.5 and bearing < 337.5
+ return t("geocoder.direction.west")
+ end
+
+ def format_name(name)
+ return name.gsub(/( *\[[^\]]*\])*$/, "")
+ end
+
+ def count_results(results)
+ count = 0
+
+ results.each do |source|
+ count += source[:results].length if source[:results]
+ end
+
+ return count
+ end
+
+ def escape_query(query)
+ return URI.escape(query, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]", false, 'N'))
+ end
+
+ def convert_latlon
+ @query = params[:query]
+
+ if latlon = @query.match(/^([NS])\s*(\d{1,3}(\.\d*)?)\W*([EW])\s*(\d{1,3}(\.\d*)?)$/).try(:captures) # [NSEW] decimal degrees
+ params[:query] = nsew_to_decdeg(latlon)
+ elsif latlon = @query.match(/^(\d{1,3}(\.\d*)?)\s*([NS])\W*(\d{1,3}(\.\d*)?)\s*([EW])$/).try(:captures) # decimal degrees [NSEW]
+ params[:query] = nsew_to_decdeg(latlon)
+
+ elsif latlon = @query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,3}(\.\d*)?)?['′]?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,3}(\.\d*)?)?['′]?$/).try(:captures) # [NSEW] degrees, decimal minutes
+ params[:query] = ddm_to_decdeg(latlon)
+ elsif latlon = @query.match(/^(\d{1,3})°?\s*(\d{1,3}(\.\d*)?)?['′]?\s*([NS])\W*(\d{1,3})°?\s*(\d{1,3}(\.\d*)?)?['′]?\s*([EW])$/).try(:captures) # degrees, decimal minutes [NSEW]
+ params[:query] = ddm_to_decdeg(latlon)
+
+ elsif latlon = @query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(\.\d*)?)?["″]?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(\.\d*)?)?["″]?$/).try(:captures) # [NSEW] degrees, minutes, decimal seconds
+ params[:query] = dms_to_decdeg(latlon)
+ elsif latlon = @query.match(/^(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(\.\d*)?)?["″]\s*([NS])\W*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(\.\d*)?)?["″]?\s*([EW])$/).try(:captures) # degrees, minutes, decimal seconds [NSEW]
+ params[:query] = dms_to_decdeg(latlon)
+ else
+ return
+ end