Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get geographic coordinates of a city in OpenStreetMap

I am new to the OpenStreetMap Api, so sorry for my basic questions: How can I get the geographic coordinates of a city given its name, using the OpenStreetMap API ? And linked to this, how can I retrieve coordinates of streets in this city ?

Thanks !

like image 323
Laurent Crivello Avatar asked Aug 11 '11 14:08

Laurent Crivello


People also ask

How do I extract coordinates from OpenStreetMap?

On the main slippy map you can right-click then click 'Show address'. The coordinates for that location will come up on the left side of the map.

Does OpenStreetMap have an API?

OpenStreetMap has an editing API for fetching and saving raw geodata from/to the OpenStreetMap database — this is the entry page for the documentation. If you just want to embed a map into a webpage, you don't want this API.

How do I get OpenStreetMap API?

The Openstreetmap API endpoint is located at http://api.openstreetmap.org/. You can find the Openstreetmap API portal / hompage here. If you need Openstreetmap API support, you can visit developer support here, or reach out to their Twitter account at @OpenStreetMap.


2 Answers

There's no way to do that using the main api, nor should you be trying to as the main api is intended primarily for editors.

What you want is the geocoder, Nominatim. You can find details of that on the wiki but basically you want to use a query like this:

http://nominatim.openstreetmap.org/search?q=paris&format=xml

Which will return an XML document listing possible matches and their locations.

like image 61
TomH Avatar answered Nov 15 '22 09:11

TomH


If you are using Python, you can use the geocoder module to retrieve the coordinates:

>>> import geocoder
>>> g = geocoder.osm('Belo Horizonte, MG, Brazil')
>>> print('Lat: {}\nLong: {}'.format(g.osm['y'], g.osm['x']))
Lat: -19.9227318
Long: -43.9450948
like image 29
Luiz Otavio V. B. Oliveira Avatar answered Nov 15 '22 09:11

Luiz Otavio V. B. Oliveira