0

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

granier
  • 1,739
  • 13
  • 25
  • It should be done in 2 steps (2 questions). 1) Find the geocoordinate of the click, assuming you are using openlayers (otherwise you will have to compute it yourself, or give us more information): https://stackoverflow.com/questions/51134894/get-coordinates-event-map-openlayers-4-6-5-5 2) Find the street/location name from the coordinates: This is called reverse-geocoding. There are services to do this, e.g. google or something free. I was happy with positionsstack https://developers.google.com/maps/documentation/geocoding/requests-reverse-geocoding https://positionstack.com/ – Wyrzutek Dec 05 '22 at 13:05
  • A great thanks @Wyrzutek for the first part. For the secondn since my purpose is to locate street in France, I can use an open data french governement API : https://adresse.data.gouv.fr/api-doc/adresse . Why do not post your comment as answer ? Like that I can close this question with your answer. – granier Dec 05 '22 at 16:27
  • Happy to help! I wanted to make sure that the question was not a duplicate of the linked one, and that you were actually using openlayers and not fetching osm directly. – Wyrzutek Dec 05 '22 at 20:21

1 Answers1

0

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.

Wyrzutek
  • 605
  • 1
  • 5
  • 13