You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Google Places API获取指定地址周边的兴趣点(POI)

解决Google Places API只返回街道地址、拿不到周边POI的问题

问题根源

你当前用的client.places(query=...)属于文本搜索逻辑,会优先匹配输入的地址字符串,所以只会返回对应的街道地址结果。另外你设置搜索半径的方式也不对——直接给googlemaps.Client类添加extra_params属性是无效的,参数得在具体请求里传递。

正确做法:先转经纬度,再用周边搜索

要获取指定地址范围内的POI,得先把地址转换成经纬度坐标,再调用**周边搜索(Nearby Search)**接口,指定搜索半径和目标POI类型(可选)。

修改后的代码

import googlemaps
import pandas as pd

# 初始化API客户端
client = googlemaps.Client('My_Google_Key_ID')
query_address = "Maskit 15, Herzliya"

# 第一步:把地址转换为经纬度坐标
geocode_result = client.geocode(query_address)
if not geocode_result:
    print("无法找到该地址的坐标信息")
    exit()
location = geocode_result[0]['geometry']['location']  # 提取纬度lat和经度lng

# 第二步:调用周边搜索接口,获取5公里范围内的POI
# 可通过types参数过滤POI类型,比如['restaurant', 'store'];不指定则返回所有非纯地址类型的结果
nearby_places = client.places_nearby(
    location=(location['lat'], location['lng']),
    radius=5000,
    # types=['point_of_interest']  # 可选:仅返回通用POI类型,按需启用
)

# 提取结果并转换为DataFrame
all_places = nearby_places["results"]
# 可选:过滤掉street_address类型的结果,只保留纯粹的POI
filtered_places = [place for place in all_places if 'street_address' not in place['types']]
results = pd.DataFrame(filtered_places)

# 打印核心信息验证
print(results[['name', 'types', 'vicinity']])

关键说明

  • places_nearby是Google Places API专门用于获取指定坐标周边POI的接口,完全匹配你的需求,比文本搜索更精准。
  • 如果需要特定类型的POI,可参考官方类型列表设置types参数,比如['cafe', 'gym']就能只返回咖啡馆和健身房。
  • 注意API调用的限额限制,高频或大量请求可能需要付费扩容。

内容的提问来源于stack exchange,提问作者Dekel Karkasoni

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 08:22:45