fix ricerca libera: geocoding via Photon (Nominatim 403 con UA QML) + osm_tag place:city
This commit is contained in:
+11
-4
@@ -149,17 +149,24 @@ Page {
|
||||
}
|
||||
|
||||
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()
|
||||
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)
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200) {
|
||||
try {
|
||||
var j = JSON.parse(xhr.responseText)
|
||||
if (j && j.length > 0) {
|
||||
cb(j[0].name || j[0].display_name.split(",")[0],
|
||||
parseFloat(j[0].lat), parseFloat(j[0].lon), "OpenStreetMap")
|
||||
if (j && j.features && j.features.length > 0) {
|
||||
var f = j.features[0]
|
||||
var name = f.properties.name || query
|
||||
cb(name,
|
||||
f.geometry.coordinates[1],
|
||||
f.geometry.coordinates[0],
|
||||
"OpenStreetMap")
|
||||
} else {
|
||||
cb(null)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user