Skip to content

Commit

Permalink
Fix geocoder to new 3.x API (#151)
Browse files Browse the repository at this point in the history
As index.html is using the latest version of leaflet-control-geocoder
and the API changed in 3.0.0 with this example:

```
Migrate from callbacks to Promise

-geocoder.geocode(query, callback);
+geocoder.geocode(query).then(callback);

-geocoder.reverse(latlng, scale, callback);
+geocoder.reverse(latlng, scale).then(callback);

Migrate from callbacks to async-await

-geocoder.geocode(query, callback);
+const results = await geocoder.geocode(query);

-geocoder.reverse(latlng, scale, callback);
+const results = await geocoder.reverse(latlng, scale);
```

The usage in the map widget also needs updating to correspond.
  • Loading branch information
SevereOverfl0w authored Jan 15, 2025
1 parent 02f5d1e commit fec8ade
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions map/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,14 @@ if (URLSearchParams && location.search && geocoder) {
}

async function geocode(address) {
return new Promise((resolve, reject) => {
try {
geocoder.geocode(address, (v) => {
v = v[0];
if (v) { v = v.center; }
resolve(v);
});
} catch (e) {
console.log("Problem:", e);
reject(e);
}
});
const results = await geocoder.geocode(address);
let v = results[0];

if (v) {
v = v.center;
}

return v;
}

async function delay(ms) {
Expand Down

0 comments on commit fec8ade

Please sign in to comment.