From 84ce69ed22bd2a01ff422d50c25caed783a72e6e Mon Sep 17 00:00:00 2001 From: mattew124 Date: Thu, 25 Apr 2024 17:25:50 +1000 Subject: [PATCH] Update geocoder.ex to include Territories The address returned by the following link returns Territory instead of state so I have added state aliases to include this information: https://nominatim.openstreetmap.org/reverse?format=xml&lat=-35.1604&lon=149.1049&zoom=19&addressdetails=1 --- lib/teslamate/locations/geocoder.ex | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/teslamate/locations/geocoder.ex b/lib/teslamate/locations/geocoder.ex index ae4771ee09..dfad132296 100644 --- a/lib/teslamate/locations/geocoder.ex +++ b/lib/teslamate/locations/geocoder.ex @@ -129,6 +129,13 @@ defmodule TeslaMate.Locations.Geocoder do "department" ] + @state_aliases [ + "state", + "province", + "territory", + "state_code" + ] + defp into_address(%{"error" => "Unable to geocode"} = raw) do unknown_address = %{ display_name: "Unknown", @@ -162,7 +169,7 @@ defmodule TeslaMate.Locations.Geocoder do city: raw["address"] |> get_first(@city_aliases), county: raw["address"] |> get_first(@county_aliases), postcode: get_in(raw, ["address", "postcode"]), - state: raw["address"] |> get_first(["state", "province", "state_code"]), + state: raw["address"] |> get_first(@state_aliases), state_district: get_in(raw, ["address", "state_district"]), country: raw["address"] |> get_first(["country", "country_name"]), raw: raw