首页 > 解决方案 > 位置应由两个数值组成

问题描述

使用 Jupyter 笔记本

制作地图

place_lat

[37.4601908,
 37.4785259,
 37.5618288,
 37.5672412,
 37.4601908,
 37.526152,
 37.504487,
 37.5277524,
 37.526152,
 37.681997,
 37.642134]

place_lng

[126.4406957,
 126.6685039,
 126.8019274,
 127.0056589,
 126.4406957,
 127.028504,
 127.048957,
 127.01948,
 127.028504,
 126.77004,
 126.8312317]

我在这里遇到错误

map = folium.Map(location=[37.4601908, 126.4406957], zoom_start=11)

for n in place_name:
    folium.Marker([place_lat,
                  place_lng]).add_to(map)

map

错误说

ValueError: Location should consist of two numerical values, but [37.4601908, 37.4785259, 37.5618288, 37.5672412, 37.4601908, 37.526152, 37.504487, 37.5277524, 37.526152, 37.681997, 37.642134] of type <class 'list'> is not convertible to float.

我应该将列表更改为浮动吗?

我该如何解决?

标签: pythonjupyter-notebookfolium

解决方案


你需要遍历你的 lat,long 列表:

for index,lat in enumerate(place_lat):
folium.Marker([lat,
               place_lng[index]]).add_to(map)

我假设你有相同的长度place_latplace_lang

enumerate在列表上将返回列表中的索引和值。


推荐阅读