Skip to content

Commit

Permalink
use bias options for autocomplete (#2122)
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyshull authored Jul 9, 2024
1 parent 41794db commit 1ce1440
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions lib/location_service/location_service.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,35 @@ defmodule LocationService do

@behaviour LocationService.Behaviour

@default_options %{
@bias_options %{
BiasPosition: [-71.0660, 42.3548],
MaxResults: 50
}
@bounding_options %{
FilterBBox: [-71.9380, 41.3193, -69.6189, 42.8266],
MaxResults: 50
}

def autocomplete(text, limit, options \\ @bias_options)

@decorate cacheable(cache: @cache, on_error: :nothing, opts: [ttl: @ttl])
def autocomplete(text, limit, options) when 1 <= limit and limit <= 15 do
Request.autocomplete(text, limit, options)
|> Result.handle_response(%{search: text, limit: limit})
end

def autocomplete(_, _, _), do: {:error, :invalid_arguments}

@decorate cacheable(cache: @cache, on_error: :nothing, opts: [ttl: @ttl])
def geocode(address, options \\ @default_options) when is_binary(address) do
def geocode(address, options \\ @bounding_options) when is_binary(address) do
Request.new(address, options)
|> Result.handle_response(address)
end

@decorate cacheable(cache: @cache, on_error: :nothing, opts: [ttl: @ttl])
def reverse_geocode(latitude, longitude, options \\ @default_options)
def reverse_geocode(latitude, longitude, options \\ @bounding_options)
when is_float(latitude) and is_float(longitude) do
Request.new([latitude, longitude], options)
|> Result.handle_response([latitude, longitude])
end

def autocomplete(text, limit, options \\ @default_options)

@decorate cacheable(cache: @cache, on_error: :nothing, opts: [ttl: @ttl])
def autocomplete(text, limit, options) when 1 <= limit and limit <= 15 do
Request.autocomplete(text, limit, options)
|> Result.handle_response(%{search: text, limit: limit})
end

def autocomplete(_, _, _), do: {:error, :invalid_arguments}
end

0 comments on commit 1ce1440

Please sign in to comment.