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

Getting Longitude & Latitude from GeoSearchControl #238

Open mhatreD opened 3 years ago

mhatreD commented 3 years ago

Hi,

I have developed below code for GeoSearchControl, but not getting Long & Lat after search is completed

const searchControl = new GeoSearchControl({ //geosearch object provider: new OpenStreetMapProvider({ params: { 'accept-language': 'en', // render results in English // countrycodes: '', // limit search results to Canada & United States }, }), style: 'button', showMarker: true, autoComplete: true, showPopup: true, autoClose: true, retainZoomLevel: false, animateZoom: true, keepResult: true, searchLabel: 'Enter Address' });

Below code is added in Class component

componentDidMount() { //Defining the offline layer for the map const map = L.map('map-id'); const offlineLayer = L.tileLayer.offline('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', localforage, { attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>', subdomains: 'abc', minZoom: 13, maxZoom: 19, crossOrigin: true }); offlineLayer.addTo(map);//add the offline layer map.zoomControl.remove(); map.addControl(searchControl); }

How can I get Longitude & Latitude when we clicked on Search Result, below is the screenshot of Search Result image

yznts commented 3 years ago

@mhatreD Please, can you provide your example as JSFiddle, or something like that? It would be very helpful. Thank you :)

phanirithvij commented 3 years ago

The question is are there any callbacks that can be added to the controller which can allow getting marker position like onResult(result, query): void and onDrag(x, y, query): void?

Just any example works they're asking for a way of getting marker position. While NOT using the providers directly and managing the state.

SalahAdDin commented 2 years ago

The question is are there any callbacks that can be added to the controller which can allow getting marker position like onResult(result, query): void and onDrag(x, y, query): void?

Just any example works they're asking for a way of getting marker position. While NOT using the providers directly and managing the state.

Could you solve this?