From 3dcae9199ff6f7707e06d772689b2714453bd148 Mon Sep 17 00:00:00 2001 From: xbgmsharp Date: Mon, 2 Oct 2023 21:40:44 +0200 Subject: [PATCH] Update reverse code, enforce english language result --- initdb/02_3_3_signalk_public_functions_py.sql | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/initdb/02_3_3_signalk_public_functions_py.sql b/initdb/02_3_3_signalk_public_functions_py.sql index 017d8ae..9486c5b 100644 --- a/initdb/02_3_3_signalk_public_functions_py.sql +++ b/initdb/02_3_3_signalk_public_functions_py.sql @@ -42,7 +42,8 @@ AS $reverse_geocode_py$ # Make the request to the geocoder API # https://operations.osmfoundation.org/policies/nominatim/ payload = {"lon": lon, "lat": lat, "format": "jsonv2", "zoom": 18} - r = requests.get(url, params=payload) + # https://nominatim.org/release-docs/latest/api/Reverse/ + r = requests.get(url, headers = {"Accept-Language": "en-US,en;q=0.5"}, params=payload) # Parse response # Option1: If name is null fallback to address field road,neighbourhood,suburb @@ -57,10 +58,10 @@ AS $reverse_geocode_py$ if r_dict["name"]: return { "name": r_dict["name"], "country_code": country_code } elif "address" in r_dict and r_dict["address"]: - if "road" in r_dict["address"] and r_dict["address"]["road"]: - return { "name": r_dict["address"]["road"], "country_code": country_code } - elif "neighbourhood" in r_dict["address"] and r_dict["address"]["neighbourhood"]: + if "neighbourhood" in r_dict["address"] and r_dict["address"]["neighbourhood"]: return { "name": r_dict["address"]["neighbourhood"], "country_code": country_code } + elif "road" in r_dict["address"] and r_dict["address"]["road"]: + return { "name": r_dict["address"]["road"], "country_code": country_code } elif "suburb" in r_dict["address"] and r_dict["address"]["suburb"]: return { "name": r_dict["address"]["suburb"], "country_code": country_code } elif "residential" in r_dict["address"] and r_dict["address"]["residential"]: