> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Upgrading from 2.x to 3.0

3.0 is a rewrite in TypeScript with a new build. The control and the built-in providers are used the same way: `new GeoSearchControl({ provider })`, the same options and the same events. What changed are the file names in the package, custom providers, and a limit on the suggestions. If you go further to 5.x, read [3.x to 4.0](/upgrading/v4.md) and [4.x to 5.0](/upgrading/v5.md) next.

## Dependencies and requirements

| Package or requirement              | 2.x                                      | 3.0                 | What to do                         |
| ----------------------------------- | ---------------------------------------- | ------------------- | ---------------------------------- |
| `leaflet`                           | not a dependency, the global `L` is used | `^1.6.0` (optional) | use Leaflet 1.6 or newer           |
| `lodash.debounce`, `nodent-runtime` | dependencies                             | none, bundled       | nothing                            |
| TypeScript types                    | not included                             | included            | drop your own declarations, if any |

### Updating the package


```jsonc title="package.json"
{
  "dependencies": {
    "leaflet-geosearch": "^2.7.0" // [!code --]
    "leaflet-geosearch": "^3.0.0" // [!code ++]
  }
}
```

The imports stay the same:

```js
import { GeoSearchControl, OpenStreetMapProvider } from 'leaflet-geosearch';
```

## Files in the package

| File                       | 2.x                      | 3.0                        |
| -------------------------- | ------------------------ | -------------------------- |
| CommonJS                   | `lib/index.js`           | `dist/geosearch.js`        |
| ES module                  | none                     | `dist/geosearch.module.js` |
| Browser build (`<script>`) | `dist/bundle.min.js`     | `dist/geosearch.umd.js`    |
| Stylesheet                 | `dist/style.css`         | `dist/geosearch.css`       |
| Stylesheet (source)        | `assets/css/leaflet.css` | `assets/css/leaflet.css`   |

If you import the stylesheet or load the browser build by path, change the path:


```js
import 'leaflet-geosearch/dist/style.css'; // [!code --]
import 'leaflet-geosearch/dist/geosearch.css'; // [!code ++]
```


```html
<script src="https://unpkg.com/leaflet-geosearch@2/dist/bundle.min.js"></script> <!-- [!code --] -->
<script src="https://unpkg.com/leaflet-geosearch@3/dist/geosearch.umd.js"></script> <!-- [!code ++] -->
```

The browser build still puts everything on `window.GeoSearch`, and Leaflet has to be loaded before it. 3.x has no `dist/bundle.min.js`. 5.x has it again, as a copy of the browser build.

## Suggestions are limited to 5

3.0 shows at most 5 suggestions, 2.x showed every result of the provider. `maxSuggestions` sets the number:


```js title="2.x → 3.0"
new GeoSearchControl({ provider });
// every result of the provider is suggested // [!code --]
// at most 5 results are suggested // [!code ++]

new GeoSearchControl({ provider, maxSuggestions: 10 });
```

## Requests use https

2.x used the protocol of the page for provider requests, so a page on `http:` asked the provider over `http:`. 3.0 always uses `https:`. Nothing to do, unless you run a provider of your own that only answers over `http:`.

## Custom providers

The base class of the providers is exported as `JsonProvider`, `Provider` is gone. `endpoint` gets `{ query, type }` instead of `{ query, protocol }`, and returns the full `https:` url:


```js
import { Provider } from 'leaflet-geosearch'; // [!code --]
import { JsonProvider } from 'leaflet-geosearch'; // [!code ++]

class MyProvider extends Provider { // [!code --]
class MyProvider extends JsonProvider { // [!code ++]
  endpoint({ query, protocol }) { // [!code --]
    return `${protocol}//example.com/search?q=${query}`; // [!code --]
  endpoint({ query }) { // [!code ++]
    return this.getUrl('https://example.com/search', { q: query }); // [!code ++]
  }

  parse({ data }) {
    return data.map((r) => ({ x: r.lon, y: r.lat, label: r.name, bounds: null, raw: r }));
  }
}
```

`parse({ data })` and the shape of a result (`x`, `y`, `label`, `bounds`, `raw`) are the same. See [Custom providers](/providers/custom-providers.md) for the current version.

The OpenStreetMap provider of 2.x looked up a picked suggestion again with `endpointReverse`. That method is gone in 3.0. Since 5.0, `provider.reverse()` does reverse geocoding: [Reverse geocoding](/usage.md#reverse-geocoding).

## New in 3.0

- the HERE, OpenCage and Algolia providers (Algolia was removed again in 4.0), and `LocationIQProvider` in the main export (2.x had the file, but didn't export it)
- `maxSuggestions`
- TypeScript types
