fix ricerca libera: geocoding via Photon (Nominatim 403 con UA QML) + osm_tag place:city

This commit is contained in:
2026-08-25 08:56:50 +02:00
parent 31725d4607
commit 0d854dd5d9
+11 -4
View File
@@ -149,17 +149,24 @@ Page {
} }
function geoXhr(query, cb) { function geoXhr(query, cb) {
// Photon (komoot) invece di Nominatim: accetta qualsiasi User-Agent
// (Nominatim risponde 403 all'UA generico inviato dalle XHR QML di Qt)
// e supporta il filtro osm_tag=place:city per le città vere.
var xhr = new XMLHttpRequest() var xhr = new XMLHttpRequest()
xhr.open("GET", "https://nominatim.openstreetmap.org/search?format=jsonv2&limit=1&q=" xhr.open("GET", "https://photon.komoot.io/api/?limit=1&osm_tag=place:city&q="
+ encodeURIComponent(query), true) + encodeURIComponent(query), true)
xhr.onreadystatechange = function() { xhr.onreadystatechange = function() {
if (xhr.readyState === 4) { if (xhr.readyState === 4) {
if (xhr.status === 200) { if (xhr.status === 200) {
try { try {
var j = JSON.parse(xhr.responseText) var j = JSON.parse(xhr.responseText)
if (j && j.length > 0) { if (j && j.features && j.features.length > 0) {
cb(j[0].name || j[0].display_name.split(",")[0], var f = j.features[0]
parseFloat(j[0].lat), parseFloat(j[0].lon), "OpenStreetMap") var name = f.properties.name || query
cb(name,
f.geometry.coordinates[1],
f.geometry.coordinates[0],
"OpenStreetMap")
} else { } else {
cb(null) cb(null)
} }