Python module for getting latitude and longitude from the name of a US city?

后端 未结 2 1125
谎友^
谎友^ 2021-02-07 05:42

I am looking for a python module which can take in the name of the city as the input and return the latitude and longitude of the input.

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-07 06:16

    Have a look at geopy. In the "getting started" documentation it shows:

    >>> from geopy import geocoders  
    >>> gn = geocoders.GeoNames()
    
    >>> print gn.geocode("Cleveland, OH 44106")
    (u'Cleveland, OH, US', (41.4994954, -81.6954088))
    
    >>> gn.geocode("Cleveland, OH", exactly_one=False)[0]
    (u'Cleveland, OH, US', (41.4994954, -81.6954088))
    

提交回复
热议问题