Python根据经纬度生成并调用地图
这篇文章是伟兄给我的稿子,总结实用、到位。另外,欢迎访问并关注他的博客:
https://jl-zhenlaixiaowei.blog.csdn.net/
在某公众号看到一个绘制地图的模块folium的介绍,感觉挺好玩,编一个根据经纬度生成并调用地图的小程序与大家分享,编写这个小程序虽然挺简单,但是遇到一些莫名其妙的小问题。
我用的开发环境是PyCharm,生成的html文件在程序直接用浏览器调用不可以,后来把文件拷贝到其他路径,又出现问题,如果是汉字的也不能直接在程序里调用,可以直接双击打开,但是我需要的是程序里直接调用,反复的折腾发现如果换成字母文件名就可以。
可能是编码的问题吧,遇到这些问题也是一种学习。
分享代码如下:
# 导入相关的模块
import folium # 地图模块
import os # 用于文件路径操作
import webbrowser # 浏览器调用
import urllib # 地址解析
from urllib import parse # 地址解析转换
import shutil # 移动文件到任意自己指定的目录
try:
hometown = input('请输入您的家乡名称:')
lat_deg = float(input('请输入您的家乡所处的纬度:'))
lon_deg = float(input('请输入您的家乡所处的经度:'))
city_Map = folium.Map(location=[lat_deg, lon_deg], zoom_start=10)
city_Map.save(f'{hometown}.html')
targetPath = ''
shutil.move(os.path.join(os.getcwd(),f'{hometown}.html'), targetPath) # 不移动文件到另一个目录,webbrower打不开
url_str = urllib.parse.quote(f'{hometown}') # 很奇怪,不解析,也无法打开
webbrowser.open('file://' + targetPath + url_str + '.html')
except:
print('请核实输入的信息!')
运行效果如下图:
关键词
模块
文件
问题
经纬度
最新评论
推荐文章
作者最新文章
你可能感兴趣的文章
Copyright Disclaimer: The copyright of contents (including texts, images, videos and audios) posted above belong to the User who shared or the third-party website which the User shared from. If you found your copyright have been infringed, please send a DMCA takedown notice to [email protected]. For more detail of the source, please click on the button "Read Original Post" below. For other communications, please send to [email protected].
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。