开发者

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 !


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜