Python,Google Places API - 给定一组纬度/经度查找附近的地点

2024-06-19

我有一个由商店 ID 及其纬度/经度组成的数据框。 我想迭代该数据框,并使用 google api 为每个商店 ID 查找附近的关键地点。

例如输入:

Store-ID  LAT       LON
     1     1.222      2.222
     2     2.334      4.555
     3     5.433      7.2343

输出应该是(在新的数据框中):

Store-ID   Places found     ......
    1          school
    1          cafe
    1          cinema
    1          bookstore
    .
    .
    .
    2          toy store
    2          KFC

等等 ..........

到目前为止,我已尝试以下操作,但无法创建与上面提到的输出格式匹配的新数据框

map_client = googlemaps.Client(API_KEY)
theta = 0
search_string =['school','store','bank','restaurant','clothing_store','health','mosque','hospital','car_dealer','finance','electronics_store','university','home_goods_store']
distance = km_to_meters(0.1)


sc = []
business_list = []
import time
import math
for i, row in POI_copy.iterrows():
 print(i, row[0], row[1], row[2])
 for string in search_string:

    coordinates = (row[1], row[2])
    response = map_client.places_nearby(
    location = coordinates,
    keyword = string,
    radius = distance
        )
    business_list.extend(response.get('results'))
    print(f'we have found a place and we are appending for store code{row[0]}')
    sc.append(str(row[0]))
    next_page_token = response.get('next_page_token')

    while next_page_token:
        time.sleep(2)
        response = map_client.places_nearby(
        location= coordinates,
        keyword=string,
        radius=distance,
        page_token=next_page_token)
        business_list.extend(response.get('results'))
        next_page_token = response.get('next_page_token')
        print(f'we have found a place and we are appending for store code{row[0]}')
        sc.append(str(row[0]))

我还想知道我们是否可以提取每个地方的更多信息,例如评级、时间、一天中最繁忙的时间、一周中最繁忙的一天并附加到数据框


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Python,Google Places API - 给定一组纬度/经度查找附近的地点 的相关文章

随机推荐