Open rainit2006 opened 5 years ago
Task 1, 解析页面 2,匹配关键词 3,生成kml文件 4,把kml文件显示在map上 5,py文件转换成可执行exe文件。
生成kml文件: 利用simplekml库
安装:
pip install simplekml
代码示例:
import simplekml
latlogs = []
kname = 'myKML.kml'
kml = simplekml.Kml()
for item in route_x:
location = item[0]
result = get_google_results(location, API_KEY)
latlogs.append([result["longitude"], result["latitude"]])
pnt = kml.newpoint(name=str(location), coords=[(float(result["longitude"]), float(result["latitude"]), float(0))])
pnt.extendeddata.newdata(name='info', value = item[1:])
#kml.newlinestring(name='LineString', coords=latlogs)
kml.save(kname)
参考: https://qiita.com/tomo001/items/b375e5fa578eb8880662
kml文件在线显示(利用下面网页) http://kmlviewer.nsspot.net/
利用Google maps API
根据出发点和终点来获得整个路线的point:利用direction API
https://maps.googleapis.com/maps/api/directions/json?origin=Disneyland&destination=Universal+Studios+Hollywood&key=YOUR_API_KEY
参考:https://developers.google.com/maps/documentation/directions/start
根据地名得到GPS经纬度:
https://maps.googleapis.com/maps/api/geocode/json?address=”場所”&key=”API KEY”
コードは下記です。
geocode_url = "https://maps.googleapis.com/maps/api/geocode/json?address={}".format(address)
geocode_url = geocode_url + "&key={}".format(api_key)
# Ping google for the reuslts:
results = requests.get(geocode_url)
# Results will be in JSON format - convert to dict using requests functionality
results = results.json()