stefanocudini / leaflet-search

Search stuff in a Leaflet map
https://opengeo.tech/maps/leaflet-search/
MIT License
780 stars 335 forks source link

JSONP broken #321

Closed svbatalov closed 1 year ago

svbatalov commented 1 year ago

Hello.

I query OSM Nominatim API via JSONP callback. Few months ago it stopped working -- whenever I try to search something, the following error is thrown:

Uncaught TypeError: L.Control.Search.callJsonp is not a function

After some investigation it turns out that recent versions call _retrieveData directly instead of using this._retrieveData.call(...), as it was before. So instead of 2 arguments (inputText and callback) the function is called with three, so inputText = this and callback = inputText.

svbatalov commented 1 year ago

Created PR #322 that should fix this.

jt196 commented 1 year ago

So, hacking around a bit with this code and the PR this last day or two. The PR does stop the error, but the search results produce an "undefined" result in the search box. I've tested this by changing the source code on the example online as well as my personal project.

Screenshot 2023-06-02 at 10 54 22

If it's any help, this is the request URL: https://nominatim.openstreetmap.org/search?format=json&q=London&json_callback=L.Control.Search.callJsonp

And this is the response:

L.Control.Search.callJsonp([{
    "place_id": 344385499,
    "licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
    "osm_type": "relation",
    "osm_id": 65606,
    "boundingbox": ["51.2867601", "51.6918741", "-0.5103751", "0.3340155"],
    "lat": "51.5073359",
    "lon": "-0.12765",
    "display_name": "London, Greater London, England, United Kingdom",
    "class": "place",
    "type": "city",
    "importance": 0.9407827616237295,
    "icon": "https://nominatim.openstreetmap.org/ui/mapicons/poi_place_city.p.20.png"
    }])