我正在尝试将 (~320+) 德克萨斯地址列表映射到 lat,lng。
我开始使用 geopy(简单示例),它适用于某些地址,但它在一组地址上失败。
所以我将备份与 googlemaps 地理编码集成在一起......但它也失败了。下面是代码...见address_to_geoPt。
然而,当我通过浏览器提交失败的地址时,它会找到地址......关于如何获得更可靠点击的任何提示?我应该使用哪个 googleapi(请参阅 address_to_geoPt_googlemaps())
class GeoMap(dbXLS):
def __init__(self, **kwargs):
super(umcGeoMap, self).__init__(**kwargs)
# Geo Locator
self.gl = Nominatim()
self.gmaps = googlemaps.Client(key='mykeyISworking')
shName = self.xl.sheet_names[0] if 'sheet' not in kwargs else kwargs['sheet']
self.df = self.xl.parse(shName)
def address_to_geoPt(self, addr):
l = self.geoLocation(addr)
if l : return (l.latitude, l.longitude)
return (np.nan, np.nan)
def address_to_geoPt_googlemaps(self, addr):
geocode = self.gmaps.geocode(addr)
if l == None : return (np.nan, np.nan)
# Geocoding an address
locDict = geocode[0]['geometry']['location']
return(locDict['lat'], locDict['lng'])
def address(self, church):
return (church.Address1 + " "
+ church.City + " "
+ church.State + " "
+ church.ZipCode + " "
+ church.Country)
def church_to_geoPt(self, church):
a = (church.Address1 + " "
+ church.City + " "
+ church.State)
if pd.isnull(church.geoPt):
(lat, lng) = self.address_to_geoPt(a)
else: (lat, lng ) = church.geoPt
if not pd.isnull(lat) :
print("DEBUG to_geoPt 1", lat, lng, a)
return (lat,lng)
(lat, lng) = self.address_to_geoPt_googlemaps(a)
print("DEBUG to_geoPt 2", lat, lng, a)
return (lat, lng)
下面显示了一组未被地理编码器映射的地址。
4 3000 Bee Creek Rd Spicewood TX 78669-5109 USA
6 P O BOX 197 BERTRAM TX 78605-0197 USA
10 2833 Petuma Dr Kempher TX 78639 USA