通过地址获取经纬度的三种方法; 通过经纬度获取省市的方法
# coding: utf-8 #通过地址获取经纬度的三种方法 #方法一 http://www.cnblogs.com/liangto/p/6287957.html中的方法二 import urllib2 import json address ='西安市高新区锦业路69号创业研发园' url = 'http://api.map.baidu.com/geocoder/v2/?address=%s'% address + '&output=json&ak=秘钥' html = urllib2.urlopen(url) json1 = html.read() #转化为str类型 hjson1 =json.loads(json1) #转化为dict类型 lng1 = hjson1['result']['location']['lng'] # 经度 lat1 = hjson1['result']['location']['lat'] # 纬度 print '方法一:',lng1,lat1 #方法二 http://blog.csdn.net/mrlevo520/article/details/52556625 import requests base = 'http://api.map.baidu.com/geocoder/v2/?address=西安市高新区锦业路69号创业研发园&output=json&ak=秘钥' response = requests.get(base) answer = response.json() lng = answer['result']['location']['lng'] lat = answer['result']['location']['lat'] print '方法二:',lng,lat #反查 baseop = 'http://api.map.baidu.com/geocoder/v2/?ak=秘钥&location=39.911013, 116.413554&output=json' responseop = requests.get(baseop) answerop = responseop.json() province = answerop['result']['addressComponent']['province'] city = answerop['result']['addressComponent']['city'] print '方法二反查:',province,city #方法三 http://blog.csdn.net/spacecraft/article/details/43309447 from geopy.geocoders import baidu apikey = '秘钥' # 从网站申请 http://lbsyun.baidu.com/apiconsole/key?application=key b = baidu.Baidu(apikey) location = b.geocode("西安市高新区锦业路69号创业研发园") print '方法三:',location.longitude,location.latitude
#反查
aa = b.reverse("22.546834, 113.946787")
ad = aa.address
p_start = ad.index('省')
p_end = ad.index('市')
print '方法三反查:',ad[:p_start+3],ad[p_start+3:p_end+3]
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 快收藏!一个技巧从此不再搞混缓存穿透和缓存击穿
· Blazor Hybrid适配到HarmonyOS系统
· 支付宝 IoT 设备入门宝典(下)设备经营篇
· 万字调研——AI生成内容检测
· 解决跨域问题的这6种方案,真香!