Python地理位置信息库geopy的使用(一):基本使用
geopy是Python关于地理位置的一个第三方库,用这个库来进行地址位置信息的查询和转换非常方便,本文介绍关于geopy的常用的几种用法
geopy的安装
pip install geopy
根据地址查询坐标及详细信息
>>> import json, logging >>> from geopy.geocoders import Nominatim >>> geolocator = Nominatim() >>> location = geolocator.geocode("北京天安门") >>> print location.address 天安门, 1, 西长安街, 崇文, 北京市, 东城区, 北京市, 100010, 中国 >>> print (location.latitude, location.longitude) (39.90733345, 116.391244079988) >>> print json.dumps(location.raw, indent=4, ensure_ascii=False, encoding='utf8') { "display_name": "天安门, 1, 西长安街, 崇文, 北京市, 东城区, 北京市, 100010, 中国", "importance": 0.00025, "place_id": "74005413", "lon": "116.391244079988", "lat": "39.90733345", "osm_type": "way", "licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright", "osm_id": "25097203", "boundingbox": [ "39.9072273", "39.9075343", "116.3906566", "116.3918428" ], "type": "yes", "class": "building" }
根据坐标信息查询地址
>>> import json, logging >>> from geopy.geocoders import Nominatim >>> geolocator = Nominatim() >>> location = geolocator.reverse("39.90733345,116.391244079988") >>> print location.address 天安门, 1, 西长安街, 崇文, 北京市, 东城区, 北京市, 100010, 中国 >>> print json.dumps(location.raw, indent=4, ensure_ascii=False, encoding='utf8') { "display_name": "天安门, 1, 西长安街, 崇文, 北京市, 东城区, 北京市, 100010, 中国", "place_id": "74005413", "lon": "116.391244079988", "boundingbox": [ "39.9072273", "39.9075343", "116.3906566", "116.3918428" ], "osm_type": "way", "licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright", "osm_id": "25097203", "lat": "39.90733345", "address": { "building": "天安门", "city": "北京市", "house_number": "1", "country": "中国", "suburb": "东城区", "state": "北京市", "postcode": "100010", "country_code": "cn", "road": "西长安街" } }

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
Java读取文件的四种方式
按字节读取文件内容 按字符读取文件内容 按行读取文件内容 随机读取文件内容 public class ReadFromFile { /** * 以字节为单位读取文件,常用于读二进制文件,如图片、声音、影像等文件。 */ public static void readFileByBytes(String fileName) { File file = new File(fileName); InputStream in = null; try { System.out.println("以字节为单位读取文件内容,一次读一个字节:"); // 一次读一个字节 in = new FileInputStream(file); int tempbyte; while ((tempbyte = in.read()) != -1) { System.out.write(tempbyte); } in.close(); } catch (IOException e) { e.printStackTrace(); return; } try { System.out.println("以字节为单位读取...
- 下一篇
算法面试题(四)
1. 问题:有一对兔子,从出生第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月也生一对兔子,假如兔子都不死,问每个月兔子的总数是多少?这个一个菲波拉契数列问题。 package test; /** * @author cz * @date 2018年7月29日 */ public class Test10 { //月 1 2 3 4 5 6 7 8 9 10 11 12 //对 1 1 2 3 5 8 13 21 34 55 89 144 public static void main(String[] args) { System.out.println("第1个月:"+1+"对"); System.out.println("第2个月:"+1+"对"); //记录月 int M=24; // int f1=1,f2=1; int f; for(int i=3;i<=M;i++){ f=f2; f2=f1+f2; f1=f; System.out.println("第"+i+"个月:"+f2+"对"); } } } 2.已知有一个数列,f(0)=1,f(1)=4,f(n+...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- MySQL8.0.19开启GTID主从同步CentOS8
- CentOS8,CentOS7,CentOS6编译安装Redis5.0.7
- CentOS7安装Docker,走上虚拟化容器引擎之路
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- SpringBoot2整合Redis,开启缓存,提高访问速度
- CentOS6,7,8上安装Nginx,支持https2.0的开启
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装
- CentOS7设置SWAP分区,小内存服务器的救世主
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果
- CentOS8编译安装MySQL8.0.19