# -*- coding: utf-8 -*- """ Created on Thu Dec 15 10:38:19 2022 @author: 李堃 """ ###使用高德地图需要进行坐标转化 import math pi = 3.1415926535897932384626 a = 6378245.0 ee = 0.00669342162296594323 def wgs_gcj(lat, lon): dLat = transform_lat(lon - 105.0, lat - 35.0) dLon = transform_lon(lon - 105.0, lat - 35.0) radLat = lat / 180.0 * pi magic = math.sin(radLat) magic = 1 - ee * magic * magic sqrtMagic = math.sqrt(magic) dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi) dLon = (dLon * 180.0) / (a / sqrtMagic * math.cos(radLat) * pi) mgLat = lat + dLat mgLon = lon + dLon return [mgLat,mgLon] def transform_lat(x, y): ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * math.sqrt(abs(x)) ret += (20.0 * math.sin(6.0 * x * pi) + 20.0 * math.sin(2.0 * x * pi)) * 2.0 / 3.0 ret += (20.0 * math.sin(y * pi) + 40.0 * math.sin(y / 3.0 * pi)) * 2.0 / 3.0 ret += (160.0 * math.sin(y / 12.0 * pi) + 320 * math.sin(y * pi / 30.0)) * 2.0 / 3.0 return ret def transform_lon(x, y): ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * math.sqrt(abs(x)) ret += (20.0 * math.sin(6.0 * x * pi) + 20.0 * math.sin(2.0 * x * pi)) * 2.0 / 3.0 ret += (20.0 * math.sin(x * pi) + 40.0 * math.sin(x / 3.0 * pi)) * 2.0 / 3.0 ret += (150.0 * math.sin(x / 12.0 * pi) + 300.0 * math.sin(x / 30.0 * pi)) * 2.0 / 3.0 return ret P = pd.read_csv("test_data.csv").values locations = P.tolist() zz=[ wgs_gcj(i[0], i[1]) for i in locations ] import folium import os import pandas as pd import numpy as np m = folium.Map(zz[0], zoom_start=16, tiles='http://webrd02.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={x}&y={y}&z={z}', attr='default') folium.PolyLine( # polyline方法为将坐标用实线形式连接起来 zz, # 将坐标点连接起来 weight=4, # 线的大小为4 color='red', # 线的颜色为红色 opacity=0.8, # 线的透明度 ).add_to(m) # 将这条线添加到刚才的区域m内 folium.Marker( location=zz[0], popup='start location', icon=folium.Icon(color='blue', icon='cloud') # 标记颜色 图标 ).add_to(m) folium.Marker( location=zz[-1], popup='end location', icon=folium.Icon(color='red', icon='cloud') # 标记颜色 图标 ).add_to(m) m.save("trace.html")