用Bing Map服务代替Yahoo的Geocoding API
Bing Map的相关网站:
Bing Map 开发者中心 publice21@outlook
Bing Map 的MSDN
Bing Map 的MSDN 另一个文档
根据Bing Map修改后的部分代码:
BingKey="AudmvxyrHM35ktbN5bLBPtVL24Yst22RTfIyRSxzr45r7aY9cW7DYB2tQt9S235_"
request="http://dev.virtualearth.net/REST/v1/Locations?query=%s&o=xml&maxResults=1&key=AudmvxyrHM35ktbN5bLBPtVL24Yst22RTfIyRSxzr45r7aY9cW7DYB2tQt9S235_"
from xml.dom.minidom import parseString
from urllib import urlopen,quote_plus
loc_cache={}
def getlocation(address):
if address in loc_cache:
return loc_cache[address]
data=urlopen(request % quote_plus(address)).read()
doc=parseString(data)
lat=doc.getElementsByTagName('Latitude')[0].firstChild.nodeValue
long=doc.getElementsByTagName('Longitude')[0].firstChild.nodeValue
loc_cache[address]=(float(lat),float(long))
return loc_cache[address]
def milesdistance(a1,a2):
lat1,long1=getlocation(a1)
lat2,long2=getlocation(a2)
latdif=69.1*(lat2-lat1)
longdif=53.0*(long2-long1)
return (latdif**2+longdif**2)**.5