基于百度API使用经纬度反查位置信息, 百度API密钥申请

1:百度API密钥申请
打开http://lbs.baidu.com/
注册成为百度开发者,通过邮件验证。打开http://lbs.baidu.com/apiconsole/key#/home 应用管理–创建应用–应用类型为服务端时 Ip填写0.0.0.0/0;应用类型为浏览器端时,IP填*. 这里我们需要创建浏览器端的应用,创建成功即可得到ak码。
2;依据经纬度信息查询地址信息

import json
import requests
from urllib.request import urlopen, quote
ak = 'ak'

address = '郑州市郑州大学'

url= 'http://api.map.baidu.com/geocoder?output=json&key=f247cdb592eb43ebac6ccd27f796e2d2&address='+str(address)
response = requests.get(url)
answer = response.json()
lon = float(answer['result']['location']['lng'])
lat = float(answer['result']['location']['lat'])
print(address,lat,lon)
print('**********************************************')
print('                                               ')


ur=r'http://api.map.baidu.com/reverse_geocoding/v3/?ak='+ak+'&output=json&coordtype=wgs84ll&location=31.225696,121.49884'
params = {'location': str(lat) + ',' + str(lon),  'output': 'json'}
res = requests.get(ur, params=params)
result = res.json()
print(result)
print('--------------------------------------------')
    #result = result['result']['formatted_address'] + ',' + result['result']['sematic_description']
result = result['result']['addressComponent']['city']

首先根据地址查询经纬度,再根据经纬度反查地址,以郑州大学为例(为了精确的获取经纬度,避免同名,最好加上省市等信息)
在这里插入图片描述
可以看到依据经纬度反查地址基本可信。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我是菜鸡,我不敢睡

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值