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 !
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With