Google Maps JavaScript API v3 Marker Animation Based Off Known Route

前端 未结 2 366
走了就别回头了
走了就别回头了 2021-01-07 09:56

I\'ve been looking for a good solution to animate a marker using the Google Maps JavaScript API V3. The marker will be animated on a predetermined path defined using latitud

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-07 10:19

    One approach is to generate a series of locations along the route (for example 500 distinct locations) and then call marker.setPosition(nextLocation) every X milliseconds using, for example, setTimeout.

    Alternatively, you can use a symbol on your polyline, setting the percentage along the path, again in a setTimeout approach. This has the advantage you don't need to compute the locations, you can just slowly move it some tiny percentage along each X milliseconds.

提交回复
热议问题