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

如何在Google Sheets中验证地址?技术方案咨询

验证Google Sheets地址并生成规范列的解决方案

用Google Maps Address Validation API实现的步骤

  • 先准备API密钥:去Google Cloud控制台启用Address Validation API,生成专属密钥,记得给密钥加使用限制(比如仅允许Google Sheets调用),防止被滥用。
  • 编写Apps Script脚本:打开你的Sheets,点「扩展程序」>「Apps Script」,把默认代码换成下面这段:
function validateAndFormatAddress(rawAddress) {
  if (!rawAddress) return "";
  
  try {
    const apiKey = "你的API密钥"; // 替换成你自己的密钥
    const url = `https://addressvalidation.googleapis.com/v1:validateAddress?key=${apiKey}`;
    
    const payload = JSON.stringify({
      address: {
        addressLines: [rawAddress]
      },
      enableUspsCass: false // 美国地址可以设为true,提升验证精度
    });
    
    const options = {
      method: "post",
      contentType: "application/json",
      payload: payload
    };
    
    const response = UrlFetchApp.fetch(url, options);
    const result = JSON.parse(response.getContentText());
    
    // 提取并拼接规范后的地址组件
    if (result.result?.address) {
      const formattedParts = [];
      const address = result.result.address;
      if (address.addressLines) formattedParts.push(...address.addressLines);
      if (address.locality) formattedParts.push(address.locality);
      if (address.administrativeArea) formattedParts.push(address.administrativeArea);
      if (address.postalCode) formattedParts.push(address.postalCode);
      if (address.countryCode) formattedParts.push(address.countryCode);
      return formattedParts.join(", ");
    } else {
      return "地址验证失败";
    }
  } catch (e) {
    return `错误: ${e.message}`;
  }
}
  • 在表格里调用函数:假设原始地址在A列,直接在B2单元格输入=validateAndFormatAddress(A2),下拉就能批量处理了。
  • 要注意的点:这个API有调用配额和收费,提前查好Google Cloud的定价;如果地址量很大,别一次性全跑,分批处理避免触发速率限制。

其他可行的替代方案

  • 用Sheets内置函数手动清洗:如果你的地址格式偏差不大,完全可以用PROPER(统一首字母大写)、REGEXREPLACE(替换多余符号)、SPLIT(拆分组件)这些组合起来规范格式,完全免费,适合小规模地址列表。
  • 第三方Sheets插件:比如「Address Validator」这类插件,基础功能免费,不用写代码,点几下就能验证格式化,适合非技术用户;但要留意插件的隐私政策,确保地址数据安全。
  • OpenStreetMap的Nominatim API:免费开源的地址验证工具,预算有限的话可以用,同样能通过Apps Script调用,但精度和覆盖范围不如Google的API,尤其是非欧美地区的地址。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 11:55:47