2

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/leaflet@1.7.1/dist/leaflet.css"/>
  <script src="https://unpkg.com/leaflet@1.7.1/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);
3

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
    },
  });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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