【问题标题】:Why am I getting this error? I need some suggestion为什么会出现此错误?我需要一些建议
【发布时间】:2022-11-16 01:52:42
【问题描述】:

未处理的运行时错误

错误:LngLatLike 参数必须指定为 LngLat 实例、对象 {lng: , lat: }、对象 {lon: , lat: } 或 [, ] 数组

 const addToMap = (map,coordinates) => {
  32 |   const marker1 = new mapboxgl.Marker()
> 33 |   .setLngLat(coordinates)
     |   ^
  34 |   .addTo(map)
  35 | }

回答 并立即提供帮助

【问题讨论】:

标签: reactjs


【解决方案1】:

这意味着您以错误的格式传递了coordinates,您可以使用其中一种格式

const coordinates = [20, 42];

// or

const coordinates = {
  lng: 20,
  lat: 42,
}

// or

const coordinates = {
  lon: 20,
  lat: 42,
}

// or

// a LngLat instance, depending on the package you are using

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-28
    • 1970-01-01
    • 2021-08-04
    • 1970-01-01
    • 2019-09-17
    • 2021-08-11
    • 1970-01-01
    • 2021-03-29
    相关资源
    最近更新 更多