smeijer / leaflet-geosearch

A geocoding/address-lookup library supporting various api providers.
https://smeijer.github.io/leaflet-geosearch/
MIT License
1.03k stars 273 forks source link

Error Cannot convert undefined or null to object #244

Closed canaliego08 closed 3 years ago

canaliego08 commented 3 years ago

Hello,

I am really new in leaflet projects so I am no preaty sure how to code this tools.

I have a map web with a leaflet map inside and I have add geosearch tool. When I have tried to search in the box, the box give me the possible results, but when I click in one of the result, the tool don not do nothing, and, in the console I can see this error:

error

<!--Add leaflet-->
<link rel="stylesheet" href="widgets/leaflet/leaflet.css"/>
<script src="widgets/leaflet/leaflet.js"></script>

<!--Add geocode openStreetMaps-->
<link   rel="stylesheet" href="https://unpkg.com/leaflet-geosearch@3.0.0/dist/geosearch.css"/>
<script src="https://unpkg.com/leaflet-geosearch@3.0.0/dist/geosearch.umd.js"></script>
<script src="widgets/leaflet-geosearch-develop/src/providers/openStreetMapProvider.ts"></script>

<script>
 /* Add basemap*/
  var map = L.map('map', { drawControl: true }, {measureControl: true}).setView([40.41108903409413, -3.7037931052124797], 12);
  L.tileLayer('{z}/{x}/{y}.png', {
    minZoom: 12,
    maxZoom: 20,
    tms: false,
    attribution: 'Generated by TilesXYZ'
  }).addTo(map);

/*Add GeoSearch tool*/
  const search = new GeoSearch.GeoSearchControl({
    retainZoomLevel: true,
    style: 'bar',
    animateZoom: true,
    provider: new GeoSearch.OpenStreetMapProvider(),
});
map.addControl(search);

</script>

Thank in advance

smeijer commented 3 years ago

You're using leaflet-geosearch 3.0, can you please upgrade to the latest version and let me know if that fixes it?

Latest as of today is 3.0.6.

canaliego08 commented 3 years ago

It's working!! thanks a lot!