leaflet latlng to name of location
Asked Answered
P

1

4

I'm creating a form where the location is being passed to an input element by default. (Basically, click on the map and the coords are default on the form) While I need to work with the coords, and I have no problem returning the coordinates, I want to show the name of the city/area of those coords in the form instead of the lat/lng.

<input type="text" id="coords_lat" name="loc_lat" value={{clickedLat}} disabled>
<input type="text" id="coords_lng" name="loc_lng" value={{clickedLng}} disabled>

Right now I'm showing like this, but I would like to show something simple like "Madrid, Spain" or even get the actual address of those coords. Is this possible to do with Leaflet?

(note i'm using meteorjs in this project)

Passageway answered 20/12, 2017 at 15:20 Comment(0)
L
5

The functionality you describe is called reverse geocoding.

You need an external service to perform such operation (like you need an external Tile Server to get raster tiles).

You can use Leaflet Control Geocoder plugin, which abstracts some of the calls to external (reverse) geocoding services:

A simple geocoder for Leaflet that by default uses OSM/Nominatim.

Luvenialuwana answered 20/12, 2017 at 15:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.