我geopy用来获取地址列表的lat/long坐标.所有文档都指向通过缓存限制服务器查询(事实上这里有许多问题),但很少有实际解决方案.
完成此任务的最佳方法是什么?
这是我正在处理的一个独立的数据处理工作...没有涉及的应用程序平台.只是尝试减少服务器查询,因为我运行的数据我以前会看到(很可能,在我的情况下).
我的代码看起来像这样:
from geopy import geocoders
def geocode( address ):
# address ~= "175 5th Avenue NYC"
g = geocoders.GoogleV3()
cache = addressCached( address )
if ( cache != False ):
# We have seen this exact address before,
# return the saved location
return cache
# Otherwise, get a new location from geocoder
location = g.geocode( address )
saveToCache( address, location )
return location
def addressCached( address ):
# What does this look like?
def …Run Code Online (Sandbox Code Playgroud)