How to display a moving track on Android device

前端 未结 1 1242
礼貌的吻别
礼貌的吻别 2021-02-04 18:30

I want to plot my track using GPS on an Android device.

I have no problem displaying a completed route but am finding it difficult to show the track as I\'m moving.

相关标签:
1条回答
  • 2021-02-04 18:52

    There's a straightforward solution using the 2.0 Maps API. You'll get a nice smooth route line using three steps:

    1. create a list of LatLng points such as:

      List<LatLng> routePoints;
      
    2. Add the route points to the list (could/should be done in a loop):

      routePoints.add(mapPoint);
      
    3. Create a Polyline and feed it the list of LatLng points as such:

      Polyline route = map.addPolyline(new PolylineOptions()
        .width(_strokeWidth)
        .color(_pathColor)
        .geodesic(true)
        .zIndex(z));
      route.setPoints(routePoints);
      

    Give it a try!

    0 讨论(0)
提交回复
热议问题