
Product
Socket Brings Supply Chain Security to skills.sh
Socket is now scanning AI agent skills across multiple languages and ecosystems, detecting malicious behavior before developers install, starting with skills.sh's 60,000+ skills.
@opencage/leaflet-opencage-geocoding
Advanced tools
Leaflet plugin for geocoding via the OpenCage Geocoder API
A Leaflet geocodig control that uses OpenCage's geocoding API.
Check out a demo page in /demo. Or take a look at the live demo.
Note: if you want location autosuggest then what you want is OpenCage's geosearch, not geocoding.
You have three options
git@github.com:opencagedata/leaflet-opencage-geocoding.gitor
or
$ bower install Leaflet.OpenCage.SearchThe control uses two image files that it expects to find in a directory with
a path relative to the control's CSS files as ../images. If you've installed
the control using Bower you'll find these in bower_components/Leaflet.OpenCage.Geocoding/dist/images/. If you've
cloned the control's GitHub repository or downloaded and unpacked an archive
from GitHub, you'll find these in dist/images.
Whichever installation method you've chosen, you'll need to move a copy of these two image files to a directory relative to the location of the control's CSS files.
Load the plugin's CSS and JavaScript files:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/opencagedata/leaflet-opencage-geocoding@v2.0.0/dist/css/L.Control.OpenCageGeocoding.min.css" />
<script src="https://cdn.jsdelivr.net/gh/opencagedata/leaflet-opencage-geocoding@v2.0.0/dist/js/L.Control.OpenCageGeocoding.min.js"></script>
Add the plugin's control to an L.Map instance:
var map = L.map('map').setView([51.52255, -0.10249], 13);
var options = {
key: 'your-api-key-here',
limit: 10,
};
var control = L.Control.openCageGeocoding(options).addTo(map);
L.tileLayer('http://tile.osm.org/{z}/{x}/{y}.png', {
attribution:
'© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors',
}).addTo(map);
By default, when a geocoding result is found, the control will center the map on it and place a marker at its location. This can be customized by overwriting the control's markGeocode function, to perform any action desired.
For example:
var control = L.Control.openCageGeocoding(options).addTo(map);
control.markGeocode = function (result) {
var bbox = result.bbox;
L.polygon([
bbox.getSouthEast(),
bbox.getNorthEast(),
bbox.getNorthWest(),
bbox.getSouthWest(),
]).addTo(map);
};
This will add a polygon representing the result's boundingbox when a result is selected.
You can overwrite the following options, for example to translate.
var options = {
key: '', // your OpenCage API key
limit: 5 // number of results to be displayed
position: 'topright',
placeholder: 'Search...', // the text in the empty search box
errorMessage: 'Nothing found.',
showResultIcons: false,
collapsed: true,
expand: 'click',
addResultToMap: true, // if a map marker should be added after the user clicks a result
onResultClick: undefined, // callback with result as first parameter
resultExtension: {
geohash: "annotations.geohash",
what3words: "annotations.what3words",
addressComponents: "components"
} //if additional attributes from OpenCage search API should be added to the result
};
var control = L.Control.openCageGeocoding(options).addTo(map);
See CONTRIBUTING.md file.
Leaflet version 0.7+
See LICENSE file.
We run the OpenCage Geocoder. Learn more about us.
We also run Geomob, a series of regular meetups for location based service creators, where we do our best to highlight geoinnovation. If you like geo stuff, you will probably enjoy the Geomob podcast.
FAQs
Leaflet plugin for geocoding via the OpenCage Geocoder API
The npm package @opencage/leaflet-opencage-geocoding receives a total of 20 weekly downloads. As such, @opencage/leaflet-opencage-geocoding popularity was classified as not popular.
We found that @opencage/leaflet-opencage-geocoding demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket is now scanning AI agent skills across multiple languages and ecosystems, detecting malicious behavior before developers install, starting with skills.sh's 60,000+ skills.

Product
Socket now supports PHP with full Composer and Packagist integration, enabling developers to search packages, generate SBOMs, and protect their PHP dependencies from supply chain threats.

Security News
An AI agent is merging PRs into major OSS projects and cold-emailing maintainers to drum up more work.