Reputation:
I using leaflet map + leaflet search plugin (https://opengeo.tech/maps/leaflet-search/examples/nominatim.html).
So, when i navigate with marker on map i want to search all places around the marker. For example the marker is located in Roma (Italy) then i want to retrieve all restaurants, night clubs .... from Roma.
Its possible to do that ??
// click on marker
map.on('click', function(e){
// update marker position
marker.setLatLng( e.latlng);
....HERE CODE TO SEARCH PLACES....
});
Upvotes: 3
Views: 3684
Reputation: 81
@Bogza You'll need to complement this plugin with anothers libraries to achive it. Nominatim is to search locations by name. Once you get the location (lat, lng) the rest of the work is up to you. You need to have a geojson or similar with the restaurants'geographical locations. Then you could try to find the nearests ones with either of these libraries: https://github.com/makinacorpus/Leaflet.GeometryUtil) using L.GeometryUtil.closestLayer. https://github.com/mapbox/leaflet-knn
PS: I had to answer because I couln't post a comment.
Upvotes: 2