小编ang*_*123的帖子

React-Google 地图车辆实时跟踪

我正在尝试通过从 api 端点获取数据来移动带有 deviceId 的选定标记。第一次渲染时,我获取最后 1 分钟的坐标数据,并将坐标推送到声明为 Path 的空数组中,每 30 秒后,我运行一个 setinterval 函数,该函数每 30 秒获取最后 30 秒的数据,然后推送Path 数组中的坐标。这是可以提供一些想法的代码:

import {
  withGoogleMap,
  withScriptjs,
  GoogleMap,
  Polyline,
  Marker
} from "react-google-maps";
const mapStyles = require("./mapStyles.json");


const Map = ({deviceId}) =>  {
  const [progress, setProgress]= useState()  
  const path= []

  const getInitialPositions = async () => {
    let from = new Date()
    let milliseconds = Date.parse(from)
    milliseconds = milliseconds - (1* 60 * 1000)
    from = new Date(milliseconds).toISOString()
    console.log(from)
    const to = new Date().toISOString()
    console.log(to) …
Run Code Online (Sandbox Code Playgroud)

fetch reactjs react-google-maps react-hooks

6
推荐指数
0
解决办法
3113
查看次数

标签 统计

fetch ×1

react-google-maps ×1

react-hooks ×1

reactjs ×1