javascript - 如何使用 MapBox 获取单个坐标数组?
问题描述
我有 55 个国家/地区的数组:
countries = ['Albania', 'Turkey', .....]
我正在寻找以下形式的单个数组:
letlocations = [ ["Albania", 11.8166, 122.0942], ["Turkey", 11.9804, 121.9189], ..... ];
目前,我只能使用此代码使用 1 个位置
const changeMapCenter = async () => {
const searchLocation = ['Madrid', 'London', 'Tokyo', 'Mexico City', 'Chicago', 'Munich', 'Machu Pichu']
let item = searchLocation[Math.floor(Math.random() * searchLocation.length)];
const searchURL = `${MAPBOX_PLACES_API}${item}${REST_PLACES_URL}`
const response = await fetch(searchURL)
const data = await response.json()
const result = data
const { coordinates } = result.features[0].geometry
const features = { coordinates }
const latlong = [...coordinates].reverse()
mymap.flyTo(latlong)
L.marker(latlong).bindPopup(`hola estás en ${item}`).addTo(mymap)
}
我的问题是如何同时绘制多个国家?
谢谢你的帮助!
解决方案
推荐阅读
- python - Python 3 // 如果字符串不包含元音则打印错误
- node.js - 如何在 mongoDB 中使用 $group 的其他自定义字段中的 count/{$sum: 1} ?
- python - 如何读取文本文件并以 UTF-8 解码?
- vue.js - Vuex:在 mapState() 中找不到 [vuex] 模块命名空间 | mapGetters(): X/
- python - 多次测量拟合曲线
- python - Python mysql池连接fetchall函数在数组中返回'u'关键字
- c# - Asp .NET MVC Core 应用程序未在 Windows Docker 容器中运行
- python - 有没有办法在opencv-python中找到闭合轮廓的中心?
- typescript - Typescript:联合函数参数类型保护
- html - 给 mat-table 一个高度并使 mat-row 可滚动