在Google我的地图中反向地理编码地点(自定义地图转街道地址)
Google我的地图地点反向地理编码最简方案
第一步:导出带经纬度的KML文件
Google我的地图的CSV导出确实只提供地点名称,但KML格式里包含了每个地点的经纬度信息:
- 打开你的自定义地图,点击左上角三条横线的菜单按钮
- 选择「导出到KML/KMZ」,勾选「仅导出包含我的地图的图层」,下载KML文件
第二步:批量生成街道地址
无代码最简法:用Google Sheets
- 打开Google Sheets,点击「文件」>「导入」,选择刚下载的KML文件,导入后会自动生成包含
Latitude(纬度)和Longitude(经度)列的表格 - 如果没有
GOOGLEMAPS_GEOCODE函数,先安装插件:点击「扩展程序」>「扩展程序市集」,搜索「Google Maps Geocoding」并安装 - 在空白列(比如C1)输入表头「街道地址」,C2单元格输入公式
=GOOGLEMAPS_GEOCODE(B2, A2)(若A列是纬度、B列是经度,可根据实际列顺序调整) - 下拉公式批量生成所有地址,最后将表格导出为CSV即可
编程法(适合有基础的用户)
用Python脚本解析KML并调用Google地图API实现批量编码:
import xml.etree.ElementTree as ET import requests import csv # 解析KML文件,替换为你的KML文件路径 tree = ET.parse('your_custom_map.kml') root = tree.getroot() ns = {'kml': 'http://www.opengis.net/kml/2.2'} locations = [] for placemark in root.findall('.//kml:Placemark', ns): name = placemark.find('kml:name', ns).text coord_text = placemark.find('.//kml:coordinates', ns).text.strip() lon, lat, _ = coord_text.split(',') locations.append((name, lat, lon)) # 替换为你的Google Maps API密钥 API_KEY = 'your_api_key' output_rows = [['地点名称', '街道地址']] for name, lat, lon in locations: api_url = f'https://maps.googleapis.com/maps/api/geocode/json?latlng={lat},{lon}&key={API_KEY}' resp = requests.get(api_url).json() if resp['status'] == 'OK': full_address = resp['results'][0]['formatted_address'] output_rows.append([name, full_address]) # 保存为CSV文件 with open('locations_with_address.csv', 'w', newline='', encoding='utf-8') as f: writer = csv.writer(f) writer.writerows(output_rows)
注意:使用API需要提前申请密钥,有免费额度,超出额度会产生费用。
内容的提问来源于stack exchange,提问作者Alex Rothberg
相关产品推荐
相关产品推荐

