TransWikia.com

TypeError when entering info in leaflet-geosearch search bar

Geographic Information Systems Asked by ale19 on July 1, 2021

I am using leaflet-geosearch. When I begin typing anything into the search bar, nothing pops up, and the developer console reads:

SearchControl.ts:28 Uncaught (in promise) TypeError: Cannot read property 'label' of undefined
    at resultFormat (SearchControl.ts:28)
    at resultList.ts:38
    at Array.forEach (<anonymous>)
    at t.e.render (resultList.ts:35)
    at SearchControl.ts:345

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 GeoSearchControl = window.GeoSearch.GeoSearchControl;
    var OpenStreetMapProvider = window.GeoSearch.OpenStreetMapProvider;
 

var provider = new OpenStreetMapProvider();

var searchControl = new GeoSearchControl({
  provider: provider,
});

map.addControl(searchControl);

One Answer

I think Openstreetmap has changed theier response data.

Simply update your code to:

var searchControl = new GeoSearchControl({
    provider: provider,
    resultFormat: function (t) {
      return '' + t.label
    },
  });

Correct answer by Falke Design on July 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP