Search code examples
openstreetmap

how to get street name from a clic on an osm map?


I would like to get the street name from a clic on an OSM map. The user displais the map of a town, zoom in and clic on a street then the application displays the street name.

Is it possible ?

For example, could it be achieved by using a rule of three with the GPS coordinates of the corners and the position of the clic in pixels ?

Bernard


Solution

  • It can be done in 2 steps.

    1. Find the geocoordinate of the click. With openlayers you can get the coordinates of a feature (see ol documentation) or even any click (see question here).

    2. Find the street/location name from the coordinates: This is called reverse-geocoding. There are services to do this, e.g. google or better something free, such as positionstack.