/opencage:opencage-geosearchfrom opencage
Integrates the OpenCage Geosearch JavaScript widget for geographic place autosuggest/autocomplete on web forms. Covers countries, cities, towns, and neighbourhoods. Works with Leaflet, OpenLayers, or MapLibre.
Ships in opencage. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
OpenCage Geosearch is a JavaScript widget that provides geographic autosuggest/autocomplete functionality for forms. It converts partial text input into place names — countries, states, regions, cities, towns, villages, and neighbourhoods. It is built on top of Algolia's Autocomplete library.
graph TD
A{User typing partial text\nin a search box?}
A -- yes --> B[Use this skill\nopencage-geosearch]
A -- no --> C{Need street addresses\nor coordinates?}
C -- yes --> D[Use opencage-geocoding-api skill\nback-end REST API]
C -- no --> E[Neither skill applies]
Type: Front-end JavaScript widget (not a REST API)
Key: oc_gs_... (different from Geocoding API key)
Package: @opencage/geosearch-bundle (CDN or npm)
Setup: opencage.algoliaAutocomplete({ container, plugins: [OpenCageGeoSearchPlugin({ key })] })
Coords: params.item.geometry.lat / .lng (in onSelect handler)
CORS: MUST register domain in OpenCage dashboard before use
Covers: Countries, cities, towns, villages, neighbourhoods — NOT street addresses or postcodes
Geosearch is not the same as the OpenCage Geocoding API. Key differences:
oc_gs_...); a Geocoding API key will not work here.If the task requires converting a complete address or coordinates server-side, use the opencage-geocoding-api skill instead.
Geosearch uses its own API key, distinct from the Geocoding API key. The key format is oc_gs_....
Obtain a key from the OpenCage dashboard after signing up at https://opencagedata.com/users/sign_up.
Before the widget will work in a browser, you must add the domain(s) it will be called from to the allowed list in your OpenCage account dashboard. Requests from unlisted domains will be blocked. This is a common integration mistake — do not skip it.
Add both the CSS and the JS bundle to your HTML:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@opencage/geosearch-bundle/dist/css/autocomplete-theme-classic.min.css" />
<script src="https://cdn.jsdelivr.net/npm/@opencage/geosearch-bundle"></script>
| Package | Use case |
|---|---|
@opencage/geosearch-bundle | Bundled version including Algolia Autocomplete — easiest to use |
@opencage/geosearch-core | Core plugin only; bring your own Algolia Autocomplete dependency |
@opencage/leaflet-opencage-geosearch | Leaflet map integration |
@opencage/ol-opencage-geosearch | OpenLayers map integration |
npm install @opencage/geosearch-bundle
You need:
<div id="place"></div>)oc_gs_...)| Parameter | Type | Description |
|---|---|---|
container | string | CSS selector for the container element |
key | string | Your Geosearch API key (oc_gs_...) |
| Parameter | Type | Default | Description |
|---|---|---|---|
bounds | string | — | Restrict results to a bounding box: "min_lon,min_lat,max_lon,max_lat" |
countrycode | string | — | ISO 3166-1 alpha-2 country code to restrict results to one or more countires (e.g. 'de' or 'gb' or 'us,ca') |
language | string | 'en' | Two-letter language code for results: de, en, es, fr, it, pt |
limit | number | 5 | Maximum number of results shown (max: 10) |
proximity | string | — | Bias results toward a coordinate: "lat,lng" |
_type | string | city | limit to or exclude one of more specific result types: 'city,postcode' or '!postcode' |
debounce | number | 300 | Milliseconds to wait after user stops typing before sending a request |
noResults | string | "No results." | Message displayed when the API returns no matches |
Pass event handlers as the second argument to OpenCageGeoSearchPlugin():
| Handler | When it fires |
|---|---|
onSelect(params) | User clicks or keyboards to a result |
onActive(params) | A result becomes the active/highlighted item |
onSubmit(params) | The form is submitted |
Each handler receives a params object containing state, event, item, and setter functions. The selected place's coordinates are at params.item.geometry.lat and params.item.geometry.lng.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@opencage/geosearch-bundle/dist/css/autocomplete-theme-classic.min.css" />
<script src="https://cdn.jsdelivr.net/npm/@opencage/geosearch-bundle"></script>
<div id="place"></div>
<script>
opencage.algoliaAutocomplete({
container: '#place',
plugins: [
opencage.OpenCageGeoSearchPlugin({
key: 'oc_gs_YOUR-KEY-HERE'
})
]
});
</script>
opencage.algoliaAutocomplete({
container: '#place',
plugins: [
opencage.OpenCageGeoSearchPlugin({
key: 'oc_gs_YOUR-KEY-HERE',
countrycode: 'de',
language: 'de',
limit: 3
}, {
onSelect: (params) => {
const { lat, lng } = params.item.geometry;
console.log('Selected coordinates:', lat, lng);
// e.g. populate hidden form fields, pan a map, etc.
}
})
]
});
The params.item object returned in onSelect contains:
params.item.geometry.lat — latitudeparams.item.geometry.lng — longitudeparams.item.formatted — human-readable place name stringThe widget can be paired with mapping libraries. Dedicated packages and tutorials are available for:
@opencage/leaflet-opencage-geosearch@opencage/ol-opencage-geosearchModern browsers are supported. For legacy browser support, include a fetch polyfill (e.g. unfetch) since the widget uses the Fetch API internally.
The widget ships with Algolia's autocomplete-theme-classic stylesheet. Appearance can be customised by overriding the CSS custom properties (variables) defined in that theme.
Geosearch returns results for: countries, states/provinces, regions, cities, towns, villages, suburbs/neighbourhoods, postcodes (for most countries), and some points of interest.
It does not return: individual street addresses or road names.
oc_gs_.... A regular Geocoding API key will not work.opencage-geocoding-api skill.autocomplete-theme-classic stylesheet. Missing the CSS makes it invisible or unstyled.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub opencagedata/opencage-skills --plugin opencage2 skills in this plugin
Other plugins' skills for the same job