Javascript 跟踪用户绘制多段线捕捉到地图

Javascript 跟踪用户绘制多段线捕捉到地图,javascript,bing-maps,Javascript,Bing Maps,我想知道是否有人有任何经验或可以帮助逻辑,跟踪用户(汽车)与必应地图 当用户旅行时,应该在他们的旅程中画一条线,但是,按照我目前设置的方式,在道路上画一条线,线穿过建筑物 因为每当位置更新时,都会计算2个点,并向地图添加一条线 (目前我正在使用watchPosition,但将来将每隔30秒获取一次位置) Bing Maps将于下周末发布一个snap-to-road API,专门为此设计。您传入GPS坐标,它会将其捕捉到道路上,此外,如果传入一组点,您还可以让它返回经过捕捉点的逻辑路径。观看Bin

我想知道是否有人有任何经验或可以帮助逻辑,跟踪用户(汽车)与必应地图

当用户旅行时,应该在他们的旅程中画一条线,但是,按照我目前设置的方式,在道路上画一条线,线穿过建筑物

因为每当位置更新时,都会计算2个点,并向地图添加一条线

(目前我正在使用watchPosition,但将来将每隔30秒获取一次位置)


Bing Maps将于下周末发布一个snap-to-road API,专门为此设计。您传入GPS坐标,它会将其捕捉到道路上,此外,如果传入一组点,您还可以让它返回经过捕捉点的逻辑路径。观看Bing地图博客的公告:

你想画线而不是穿过建筑物吗?是的,沿着道路,汽车向下移动。为什么你不使用google direction api来计算两点之间的路径?我只能使用Bing,说来话长,就是这样,我害怕从watchPosition获取点,并使用方向api获取道路上这些点之间的路径
  watchPos() {
    let options = { timeout: 60000 }
    this.watchId = navigator.geolocation.watchPosition((position) => {
      this.lat = position.coords.latitude;
      this.lng = position.coords.longitude;
      this.setMap()
      console.log(this.lat, this.lng)
    }, this.errorHandler, options);

  }
  setMap() {
    this.loc = new Microsoft.Maps.Location(this.lat, this.lng);
    if (!this.initialised) {
      this.oldLoc = this.loc;
      this.initialised = true
      this.map = new Microsoft.Maps.Map(this.driveMap.nativeElement, {
        credentials: CONFIG.BING_API_KEY,
        center: this.loc,
        mapTypeId: Microsoft.Maps.MapTypeId.road,
        navigationBarMode: 2,
        zoom: this.zoom
      });
      this.user = new Microsoft.Maps.Pushpin(this.loc, { icon: '../images/icon.svg' });
      this.map.entities.push(this.user);
      // console.log(loc)
    } else {
      // Draw line
      // from this.oldLoc to this.loc
      let lineVertices = new Array(this.oldLoc, this.loc);
      let line = new Microsoft.Maps.Polyline(lineVertices);
      // Then set oldLoc to new loc
      this.oldLoc = this.loc
      this.map.entities.push(line);
      this.map.setView({
        center: this.loc
      });
      this.user.setLocation(this.loc);
    }
  }