Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
* version 2.5.0 - 2026-08-27
* Fix: `reverse()` now builds its own `q=lat,lng` query instead of stringifying the location object
* Fix: `reverseQueryParams` was declared but never used. Now used, added tests

* version 2.4.2 - unreleased
* Demo page: the map click handler uses `reverse()` rather than hand-building a coordinate string
* Fix: demo page escapes HTML before inserting it into the DOM
* Code cleanup: replace deprecated `__dirname` in the vite config
* Code cleanup: the Github Action workflow now only requests read permissions
* Node v18 is no longer supported
* Build process: Node v18 is no longer supported
* created a CHANGED.md file and backfilled
* NPM package updates: vite, js-yaml, undici, postcss, dev dependencies

Expand Down
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,42 @@ var options = {
geohash: "annotations.geohash",
what3words: "annotations.what3words",
addressComponents: "components"
} //if additional attributes from OpenCage search API should be added to the result
}, //if additional attributes from OpenCage search API should be added to the result
geocodingQueryParams: {}, // extra query parameters sent with forward geocoding requests
reverseQueryParams: {} // extra query parameters sent with reverse geocoding requests
};

var control = L.Control.openCageGeocoding(options).addTo(map);

```

Any [OpenCage API parameter](https://opencagedata.com/api#forward-opt) can be
passed via `geocodingQueryParams` and `reverseQueryParams`, for example
`{ language: 'de', countrycode: 'de' }`.

## Reverse geocoding

The geocoder can also be used directly, without the control, to turn coordinates
into a place name or addresss:

```javascript
var geocoder = L.Control.OpenCageGeocoding.geocoder({
key: 'your-api-key-here',
});

map.on('click', function (e) {
// the second argument (scale) is ignored
geocoder.reverse(e.latlng, map.getZoom(), function (results) {
if (results[0]) {
L.marker(results[0].center).addTo(map);
}
});
});
```

`reverse()` accepts anything `L.latLng()` does: `L.LatLng` object, `[lat, lng]`
array or `{lat, lng}`. It throws a `TypeError` for anything else.

## Contributing

See `CONTRIBUTING.md` file.
Expand Down
4 changes: 2 additions & 2 deletions demo/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ <h3>✨ Modernization Features</h3>
}

map.on('click', function (e) {
const query = e.latlng.lat.toString() + ',' + e.latlng.lng.toString();
geocoder.geocode(query, function (results) {
// scale is ignored by the OpenCage geocoder, but IGeocoder requires it
geocoder.reverse(e.latlng, map.getZoom(), function (results) {
const r = results[0];
if (r) {
console.log('📌 Reverse geocoding result:', r);
Expand Down
35 changes: 27 additions & 8 deletions dist/js/L.Control.OpenCageGeocoding.dev.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/js/L.Control.OpenCageGeocoding.dev.js.map

Large diffs are not rendered by default.

35 changes: 27 additions & 8 deletions dist/js/L.Control.OpenCageGeocoding.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/js/L.Control.OpenCageGeocoding.esm.js.map

Large diffs are not rendered by default.

Loading