Google Maps API:如何使用 Talordata 采集 Google Maps 结果

了解如何使用 Talordata SERP API 采集 Google Maps 结果,并用 Python 收集商家名称、评分、评论数、地址、电话、网站、place ID、坐标,最后导出为 CSV。

Google Maps API:如何使用 Talordata 采集 Google Maps 结果
Cecilia Hill
最后更新于
9 分钟阅读

Google Maps results 很适合用于 local SEO、lead generation、competitor research、market analysis 和 AI workflows。

例如,你可能想采集:

  • Austin 的牙医

  • Seattle 的咖啡店

  • JFK Airport 附近的酒店

  • Chicago 的水电维修商家

  • New York 的餐厅

  • 某个坐标附近的 local competitors

在这篇文章中,“Google Maps API”指的是通过 Talordata SERP API 采集 Google Maps-style search results。它不是 Google 官方的 Maps Platform APIs。

Talordata SERP API 支持 Google 和其他主要搜索引擎的 structured SERP data,提供 JSON / HTML response formats 和 geo-targeted SERP data。其产品页也列出了 Google Local 和 Maps 等 result types。

我们要做什么?

我们会建立一个 Python script:

Search query
→ Talordata SERP API
→ Google Maps results
→ Extract business fields
→ Normalize data
→ Export results to CSV

最终 CSV 可以包含:

  • business name

  • ranking position

  • rating

  • review count

  • category

  • address

  • phone number

  • website

  • place ID

  • latitude

  • longitude

  • Google Maps URL

  • opening status

  • collected timestamp

Talordata 的 Google Maps SERP API guide 提到,实用的 Maps responses 通常会包含 business name、place ID、address、latitude / longitude、category、rating、review count、rank position、opening status、phone number、website、Google Maps URL、thumbnail,以及可用时的 price level。

为什么用 SERP API 采集 Google Maps?

你可以尝试用 browser automation 直接抓 Google Maps,但流程很容易变得脆弱。

常见问题包括:

  • dynamic rendering

  • infinite scrolling

  • changing layouts

  • location-specific results

  • anti-bot checks

  • CAPTCHA challenges

  • duplicate listings

  • missing addresses

  • inconsistent business names

SERP API 会让流程更干净。你发送 query 和 location,然后获取 structured data,后续更容易存储、比较和分析。

这对 local SEO 特别有用,因为 Google Maps rankings 很受 location 影响。Talordata 的 Google Maps guide 提到,在 restaurants、urgent care、salons、gyms、storage、home services 等密集市场中,一英里的位置变化就可能影响显示哪些商家。

Step 1:准备 API Key

创建 Talordata 账号,并从 dashboard 获取 SERP API key。

Talordata 产品页说明,新用户可获得 1,000 free API responses,SERP API plans 采用 response-based 方案。

把 API key 和 endpoint 设为 environment variables。

export TALORDATA_API_KEY="your_api_key_here"
export TALORDATA_SERP_ENDPOINT="your_talordata_serp_endpoint_here"

Windows PowerShell:

$env:TALORDATA_API_KEY="your_api_key_here"
$env:TALORDATA_SERP_ENDPOINT="your_talordata_serp_endpoint_here"

安装 Python package:

pip install requests

请使用 Talordata dashboard 或 API docs 中显示的 endpoint 和 parameter names。下面的代码把 request layer 分开,方便你调整实际 endpoint。

Step 2:发送 Google Maps Request

Google Maps SERP request 通常需要 query、location、language、country 和 result count。

import os
import requests


TALORDATA_API_KEY = os.getenv("TALORDATA_API_KEY")
TALORDATA_SERP_ENDPOINT = os.getenv("TALORDATA_SERP_ENDPOINT")


def require_env(name):
    value = os.getenv(name)
    if not value:
        raise RuntimeError(f"Missing required environment variable: {name}")
    return value


def search_google_maps(query, location="United States", language="en", country="us"):
    api_key = require_env("TALORDATA_API_KEY")
    endpoint = require_env("TALORDATA_SERP_ENDPOINT")

    payload = {
        "engine": "google_maps",
        "q": query,
        "location": location,
        "hl": language,
        "gl": country,
        "num": 20,
        "output": "json"
    }

    headers = {
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json"
    }

    response = requests.post(
        endpoint,
        json=payload,
        headers=headers,
        timeout=30
    )

    response.raise_for_status()
    return response.json()

有些 API 会使用 query 而不是 q,或使用 type=maps 而不是 engine=google_maps。把这个 function 独立出来,可以让你只改一处 request code。

Step 3:提取 Google Maps Results

不同 SERP APIs 可能会把 Maps results 放在不同 keys 下,例如:

local_results
maps_results
places_results

使用 flexible parser 可以让 script 更容易调整。

from datetime import datetime, timezone
from urllib.parse import urlparse


def clean_text(value):
    if not value:
        return ""
    return " ".join(str(value).split())


def get_domain(url):
    if not url:
        return ""
    parsed = urlparse(url)
    return parsed.netloc.replace("www.", "") if parsed.netloc else ""


def get_maps_results(serp_json):
    return (
        serp_json.get("maps_results")
        or serp_json.get("local_results")
        or serp_json.get("places_results")
        or []
    )


def normalize_maps_results(serp_json, query, location):
    results = get_maps_results(serp_json)
    collected_at = datetime.now(timezone.utc).isoformat()

    rows = []

    for index, item in enumerate(results, start=1):
        gps = item.get("gps_coordinates") or {}

        website = item.get("website") or item.get("link") or ""
        maps_url = item.get("maps_url") or item.get("google_maps_url") or ""

        rows.append({
            "query": query,
            "location": location,
            "position": item.get("position") or item.get("rank") or index,
            "business_name": clean_text(item.get("title") or item.get("name")),
            "category": clean_text(item.get("type") or item.get("category")),
            "rating": item.get("rating"),
            "reviews": item.get("reviews") or item.get("reviews_count"),
            "address": clean_text(item.get("address")),
            "phone": clean_text(item.get("phone")),
            "website": website,
            "website_domain": get_domain(website),
            "place_id": item.get("place_id") or item.get("data_id") or item.get("data_cid") or "",
            "latitude": gps.get("latitude") or item.get("latitude"),
            "longitude": gps.get("longitude") or item.get("longitude"),
            "opening_status": clean_text(item.get("open_state") or item.get("hours")),
            "maps_url": maps_url,
            "collected_at": collected_at
        })

    return rows

place_id 很重要。Talordata 的 Google Maps guide 提到,商家名称可能改变,连锁店可能使用相似 label,地址格式也可能不同,因此 place ID 有助于 deduplication 和 historical tracking。

Step 4:导出结果到 CSV

接着把 normalized rows 写入 CSV file。

import csv


CSV_COLUMNS = [
    "query",
    "location",
    "position",
    "business_name",
    "category",
    "rating",
    "reviews",
    "address",
    "phone",
    "website",
    "website_domain",
    "place_id",
    "latitude",
    "longitude",
    "opening_status",
    "maps_url",
    "collected_at"
]


def export_to_csv(rows, filename="google_maps_results.csv"):
    if not rows:
        print("No Google Maps results found.")
        return

    with open(filename, mode="w", newline="", encoding="utf-8") as file:
        writer = csv.DictWriter(file, fieldnames=CSV_COLUMNS)
        writer.writeheader()
        writer.writerows(rows)

    print(f"Exported {len(rows)} results to {filename}")

完整 Python 示例

import os
import csv
import requests

from datetime import datetime, timezone
from urllib.parse import urlparse


CSV_COLUMNS = [
    "query",
    "location",
    "position",
    "business_name",
    "category",
    "rating",
    "reviews",
    "address",
    "phone",
    "website",
    "website_domain",
    "place_id",
    "latitude",
    "longitude",
    "opening_status",
    "maps_url",
    "collected_at"
]


def require_env(name):
    value = os.getenv(name)
    if not value:
        raise RuntimeError(f"Missing required environment variable: {name}")
    return value


def clean_text(value):
    if not value:
        return ""
    return " ".join(str(value).split())


def get_domain(url):
    if not url:
        return ""
    parsed = urlparse(url)
    return parsed.netloc.replace("www.", "") if parsed.netloc else ""


def search_google_maps(query, location="United States", language="en", country="us"):
    api_key = require_env("TALORDATA_API_KEY")
    endpoint = require_env("TALORDATA_SERP_ENDPOINT")

    payload = {
        "engine": "google_maps",
        "q": query,
        "location": location,
        "hl": language,
        "gl": country,
        "num": 20,
        "output": "json"
    }

    headers = {
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json"
    }

    response = requests.post(
        endpoint,
        json=payload,
        headers=headers,
        timeout=30
    )

    response.raise_for_status()
    return response.json()


def get_maps_results(serp_json):
    return (
        serp_json.get("maps_results")
        or serp_json.get("local_results")
        or serp_json.get("places_results")
        or []
    )


def normalize_maps_results(serp_json, query, location):
    results = get_maps_results(serp_json)
    collected_at = datetime.now(timezone.utc).isoformat()

    rows = []

    for index, item in enumerate(results, start=1):
        gps = item.get("gps_coordinates") or {}

        website = item.get("website") or item.get("link") or ""
        maps_url = item.get("maps_url") or item.get("google_maps_url") or ""

        rows.append({
            "query": query,
            "location": location,
            "position": item.get("position") or item.get("rank") or index,
            "business_name": clean_text(item.get("title") or item.get("name")),
            "category": clean_text(item.get("type") or item.get("category")),
            "rating": item.get("rating"),
            "reviews": item.get("reviews") or item.get("reviews_count"),
            "address": clean_text(item.get("address")),
            "phone": clean_text(item.get("phone")),
            "website": website,
            "website_domain": get_domain(website),
            "place_id": item.get("place_id") or item.get("data_id") or item.get("data_cid") or "",
            "latitude": gps.get("latitude") or item.get("latitude"),
            "longitude": gps.get("longitude") or item.get("longitude"),
            "opening_status": clean_text(item.get("open_state") or item.get("hours")),
            "maps_url": maps_url,
            "collected_at": collected_at
        })

    return rows


def export_to_csv(rows, filename="google_maps_results.csv"):
    if not rows:
        print("No Google Maps results found.")
        return

    with open(filename, mode="w", newline="", encoding="utf-8") as file:
        writer = csv.DictWriter(file, fieldnames=CSV_COLUMNS)
        writer.writeheader()
        writer.writerows(rows)

    print(f"Exported {len(rows)} results to {filename}")


if __name__ == "__main__":
    query = "coffee shops in Seattle"
    location = "Seattle, Washington, United States"

    serp_json = search_google_maps(
        query=query,
        location=location,
        language="en",
        country="us"
    )

    rows = normalize_maps_results(serp_json, query, location)
    export_to_csv(rows)

执行后会生成:

google_maps_results.csv

Example Output

CSV 可能像这样:

query,location,position,business_name,category,rating,reviews,address,phone,website,website_domain,place_id,latitude,longitude,opening_status,maps_url,collected_at
coffee shops in Seattle,"Seattle, Washington, United States",1,Example Coffee,Coffee shop,4.7,1200,"123 Example St",+1 000-000-0000,https://example.com,example.com,abc123,47.61,-122.33,Open,https://maps.google.com/example,2026-06-22T00:00:00Z

接下来可以把数据发送到 Google Sheets、database、local SEO dashboard 或 AI agent workflow。

常用参数

Google Maps scraping workflows 通常会用到这些参数:

Parameter

为什么重要

q

Local search query

location

Target city、region 或 area

gl

Country or market

hl

Language

num

Number of results

coordinates

如果 API 支持,可用于 geo-grid tracking

device

用于比较 mobile 和 desktop behavior

对严肃的 local SEO analysis 来说,city-level location 往往不够。Talordata 的 Google Maps guide 提到,Maps visibility 可能会因 coordinate 改变;geo-grid 可以显示 business 在哪里可见、哪里被 competitors 压制,以及 Google 在哪些区域不再认为该 business 具备地理相关性。

常见使用场景

Local SEO rank tracking

追踪商家在 “dentist near me”、“coffee shop in Seattle” 或 “emergency plumber in Austin” 这类 local keywords 下的排名。

Competitor monitoring

比较一个本地市场中的 business names、rankings、ratings、review counts、categories 和 websites。

Lead generation

采集 business names、categories、websites、phone numbers 和 addresses,用于定向 outreach。

Geo-grid visibility analysis

在多个 coordinates 下运行同一个 query,了解 business 在哪些区域出现或消失。

AI and RAG workflows

把 Google Maps results 当成 local discovery layer。AI agent 可以基于 structured Maps data 总结 local competitors、识别 high-review businesses,或生成 market overview。

Best Practices

尽可能保存 place IDs。它能帮助你在不同 runs 中匹配同一个 business。

保存 timestamps。Ratings、review counts、opening status 和 rankings 都会变。

分离 raw data 和 normalized data。保留 raw responses 用于 debug,再将字段 normalize 后进入 dashboard。

不要在未标记的情况下混合 paid 和 organic visibility。Sponsored listings 会让 rank reports 变得不准。Talordata 的 Google Maps guide 建议,尽可能保存 sponsored flag。

严肃 local tracking 要使用 coordinates。单一 city-level query 可能会掩盖 neighborhood-level 差异。

FAQ

可以用 Python 采集 Google Maps 吗?

可以。你可以用 Python 搭配 Google Maps SERP API 发送 local query,并获取 structured business results。上面的 script 示范了如何 normalize response 并导出为 CSV。

Google Maps API 和 Google Maps SERP API 是同一件事吗?

不是。这篇文章中的 Google Maps API 指的是通过 Talordata SERP API 采集 Google Maps-style search results。Google 官方 Maps Platform APIs 是另一类产品。

Google Maps results 可以采集哪些数据?

常见字段包括 business name、ranking position、rating、review count、category、address、phone number、website、place ID、latitude、longitude、opening status 和 Google Maps URL。

为什么 place ID 很重要?

Place ID 可以帮助你在多次抓取中识别同一个 business,即使 business name、address formatting 或 listing details 发生变化。

可以用于 local SEO 吗?

可以。Google Maps data 适合 local rank tracking、competitor analysis、review monitoring、geo-grid visibility checks 和 client reporting。

立即开展您的数据业务

加入全球最强大的代理网络

免费试用