Python 地点转化为经纬度

1.geopy包下载地点 https://pypi.python.org/pypi/geopy

2.安装步骤 

           运行cmd,切换到D:/python/geopy-1.11.0/目录下(根据自己解压缩后的目录和下载的版本号修改),
    cd  D:/python//geopy-1.11.0
    运行命令:
    setup.py build
    setup.py install
           
    然后在geopy-1.11.0目录下有一个geopy文件夹  把这个文件夹拷贝到D:/python目录下
3.
方法1
 
addresses=open('C:\Users\Yilin.Wei\Documents\HR\cities6.txt')
 
from geopy.geocoders import GoogleV3
for add in addresses:
    geolocator = GoogleV3()
    
    try:
        address, (latitude, longitude) = geolocator.geocode(add)
        pr=address+"@"+str(latitude)+"@"+str(longitude)
        print (pr)
    except TypeError:
        pr=address+"@"+"NA"
        print (pr)
 
方法2
addresses=open('C:\Users\Yilin.Wei\Documents\HR\cities3.txt')
from geopy.geocoders import Nominatim
for add in addresses:
    geolocator = Nominatim()
    try:
        location = geolocator.geocode(add)
        print add,((location.latitude, location.longitude))
    except AttributeError:
        print (add, "N/A")
posted @ 2016-09-14 15:44  IT小甲鱼  阅读(3713)  评论(1编辑  收藏  举报