通过百度地图API在地图上批量添加点标注

本文介绍如何通过Python脚本,利用百度地图API从Excel导入地址获取经纬度,将结果保存到新的文件中,并进一步使用这些经纬度在地图上批量标注地点的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

通过导入Excel文件(包含一列需要标注的地址),通过百度地图经纬度转换得到需要标注地点的经纬度(保存在经纬度.xlsx),然后再通过导入经纬度.xlsx通过百度地图api批量在地图上标注地点。

首先先到百度地图开放平台百度地图开放平台 | 百度地图API SDK | 地图开发 (baidu.com)得到自己的ak,放到下面代码的相应位置就好了。

下面代码可以得到经纬度或者是详细地址:

# coding:utf-8
from urllib.request import quote
import requests
import pandas as pd

pd.set_option('display.width', 1000)
pd.set_option('display.max_columns', None)

import json

# 通过百度地图地理查询和逆地址查询
def get_location(address):
    try:
        url = 'http://api.map.baidu.com/place/v2/search?query={}&region=标注范围&output=json&ak=你的ak&scope=2'.format(quote(address))
        response = requests.get(url)
        result = response.json()
        if result['status'] == 0 and result['results']:
            lng = result['results'][0]['location']['lng']
            lat = result['results'][0]['location']['lat']
            return lng, lat
    except Exception as e:
        print(f"Failed to get location for {address}: {e}")
    return '', ''

def get_address(lng, lat):
    try:
        url = 'http://api.map.baidu.com/reverse_geocoding/v3/?'
        output = 'json'
        ak = 'BXottO3XSK3SKXn99fHquBoPo620cExI'
        uri = url + '&output=' + output + '&ak=' + ak + '&location=' + str(lat) + ',' + str(lng)
        res
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值