我通过使用此处的代码将 Google Places API 与 Python 结合使用。
我得到了这样一种类型的位置的纬度和经度:
{u'lat': Decimal('19.1156005'), u'lng': Decimal('72.9090715')}
{u'lat': Decimal('19.116867'), u'lng': Decimal('72.90982199999999')}
{u'lat': Decimal('19.1161942'), u'lng': Decimal('72.90909789999999')}
现在我想将它保存为带有纬度和经度列的数据框。我怎样才能做到这一点?
这是我使用的代码 from googleplaces import GooglePlaces, types, lang
def GoogPlaces(lat,lng,radius,types,value,key):
API_KEY = key
LOCATION = str(lat) + "," + str(lng)
RADIUS = radius
TYPES = "bus_station"
google_places = GooglePlaces(API_KEY)
query_result = google_places.nearby_search(
location=LOCATION , keyword="bus_station",
radius=RADIUS)
if query_result.has_attributions:
print query_result.html_attributions
for place in query_result.places:
print place.geo_location
for item in pointofinterest:
a = GoogPlaces(lat, lng, radius, item, value,'Mykey')
试试这个:
df = pd.DataFrame(columns = ['lat','lng'])
ctr = 0
for place in query_result.places:
for key, item in place.geo_location.items():
df.loc[ctr, key] = item
ctr += 1
这允许您为返回的每个地理空间值迭代数据帧,并使用ctr
.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句