要記得先另外安裝 QtWebEngineWidgets
package
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import QWebEngineView
import gmplot
from pathlib import Path
class window(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
vbox = QVBoxLayout(self)
apikey = 'XXXXXX' # (your API key here)
gmap = gmplot.GoogleMapPlotter(30.3164945, 78.03219179999999, 12, apikey=apikey)
# 測試繪製座標
latitude_list = [30.3358376, 30.307977, 30.3216419]
longitude_list = [77.8701919, 78.048457, 78.0413095]
# 畫點
gmap.scatter(latitude_list, longitude_list, '#FF0000', size=40, marker=False)
# 畫線
gmap.plot(latitude_list, longitude_list, 'cornflowerblue', edge_width=2.5)
# 產出的檔名
filename = 'map.html'
# Draw the map to an HTML file:
gmap.draw(filename)
# 取得當前路徑
currentPath = Path(__file__).parent.absolute()
# 完整的檔案路徑
fullFilePath = "file://" + str(currentPath) + "/" + filename
# 利用 QWebEngineView 讓 google map 顯示在畫面上
view = QWebEngineView()
view.load(QUrl(fullFilePath))
vbox.addWidget(view)
if __name__ == '__main__':
app = QApplication(sys.argv)
w = window()
w.show()
sys.exit(app.exec_())
GoogleMaps
因不支援副檔名為xmls的檔案,故須透過 offiece 轉成xls,也不能直接從檔名改,否則一樣不支援 Ref. Localizable.strings2Excel
Jun 1, 2022Ref. Python内置库:configparser(INI格式配置文件解析)
Oct 25, 2021Ref. 【python的異常處理】異常的捕捉
Jul 22, 2021調整了範例,讓 timer t 可在任意位置取消 timer 的運作,指令 t.cancel() import threading # global t t = None def set_interval(func, sec): global t
Jul 21, 2021or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up