I'm using leaflet-geosearch. When I click on an address from the search bar, I get the error:

Uncaught (in promise) TypeError: Cannot convert undefined or null to object at Function.keys () at NewClass.showResult (SearchControl.ts:412:28) at SearchControl.ts:404:12

Here is the code snippet:

  <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"/>
  <script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
  <!--initialize geosearch -->
  <link  href="https://unpkg.com/leaflet-geosearch@latest/assets/css/leaflet.css" rel="stylesheet" />
        <script src="https://unpkg.com/leaflet-geosearch@latest/dist/bundle.min.js"></script>   

var map

function createMap() {

    map = L.map('map').setView([41, -74], 9);

    L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
        maxZoom: 19,
        attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'

    const search = new GeoSearch.GeoSearchControl({
        provider: new GeoSearch.OpenStreetMapProvider(),
        /*not working
        params: {
            countrycodes: 'us'
        style: 'bar',
        showMarker: true, // optional: true|false  - default true
        showPopup: false, // optional: true|false  - default false
        marker: {
            // optional: L.Marker    - default L.Icon.Default
            icon: new L.Icon.Default(),
            draggable: false,

    //not working
    function searchEventHandler(result) {

    //not working
    map.on('geosearch/showlocation', searchEventHandler);
  • It looks like users are reporting similar issues on Github for that plugin (github.com/smeijer/leaflet-geosearch/issues). I suggest keeping tabs on those issues to see if the developers post a fix that could apply to your situation as well.
    – rumski20
    Commented Jun 14, 2022 at 13:27

1 Answer 1


I had the same issue. It was because of a bug in version 3.0.0. In your case you point the "latest" js file so it should work already. Here is the article I found my solution:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.