Google Maps API:如何使用 Talordata 擷取 Google Maps 結果

了解如何使用 Talordata SERP API 擷取 Google Maps 結果,並用 Python 收集商家名稱、評分、評論數、地址、電話、網站、place ID、座標,最後匯出為 CSV。

talor ai
最后更新于
8 分钟阅读

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。

立即开展您的数据业务

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

免费试用