让ChatGPT在实际地图上画个框

看到一新闻,新闻内容中有四个经纬度坐标,第一反应是想看看其在实际地图上的具体位置、形状和大小。四个经纬度如下:
A:25°31′00″N/119°56′00″E;
B:25°24′00″N/119°56′00″E;
C:25°24′00″N/120°03′00″E;
D:25°31′00″N/120°03′00″E。

遂让ChatGPT解决。其用Python代码,调用folium库生成Html。打开html,就是想要的效果。给ChatGPT的表现打个满分💯

Python代码:

import folium

# Define coordinates for points A, B, C, D
coordinates = [
    [25 + 31/60, 119 + 56/60],  # A: (Latitude, Longitude)
    [25 + 24/60, 119 + 56/60],  # B
    [25 + 24/60, 120 + 3/60],   # C
    [25 + 31/60, 120 + 3/60]    # D
]

# Calculate the center for initializing the map
center_lat = (coordinates[0][0] + coordinates[1][0]) / 2
center_lon = (coordinates[0][1] + coordinates[2][1]) / 2

# Create a map centered around the region
m = folium.Map(location=[center_lat, center_lon], zoom_start=11)

# Add the polygon to the map
folium.Polygon(
    locations=coordinates,
    color='blue',
    weight=2,
    fill=True,
    fill_color='blue',
    fill_opacity=0.3
).add_to(m)

# Save the map to an HTML file
map_path = "/mnt/data/region_map.html"
m.save(map_path)

# Provide the file path to the user
map_path

生成html页面如下:

html页面效果如下,地图采用的是OpenStreetMap

发表评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注