Python 对城市进行地理编码


CODE:

#!/usr/bin/python 
# -*- coding: utf-8 -*-

'''
Created on 2014-8-20
@author: guaguastd
@name: geocode_location_bing.py
'''

from geopy import geocoders

GEO_APP_KEY = ''
g = geocoders.Bing(GEO_APP_KEY)
for city in ["Beijing", "Nashville", "NewYork"]:
    print g.geocode(city, exactly_one=False)

RESULT:

[Location(Beijing, Beijing, China 39 54m 0.0s N, 116 23m 0.0s E)]
[Location(Nashville, TN, United States 36 10m 0.0s N, 86 47m 0.0s W), Location(Nashville, IN, United States 39 13m 0.0s N, 86 15m 0.0s W), Location(Nashville, IL, United States 38 21m 0.0s N, 89 23m 0.0s W), Location(Nashville, AR, United States 33 57m 0.0s N, 93 51m 0.0s W), Location(Nashville, NC, United States 35 58m 0.0s N, 77 58m 0.0s W)]
[Location(New York, NY, United States 40 47m 0.0s N, 73 50m 0.0s W), Location(New York, NY, United States 40 43m 0.0s N, 74 0m 0.0s W), Location(New York, MO, United States 39 41m 0.0s N, 93 55m 0.0s W), Location(New York, England, United Kingdom 53 5m 0.0s N, 0 8m 0.0s W), Location(New York, England, United Kingdom 54 4m 0.0s N, 1 42m 0.0s W)]


评论关闭