0

I am able to retrieve new lat and long values on location update and update the new lat and long to their respective textviews as shown below:

private Polyline route = null;
private PolylineOptions routeOpts = null;
private boolean drawTrack = true;

   private void updateUI() {
    if (mCurrentLocation != null) {
        tvLat.setText(String.valueOf(mCurrentLocation.getLatitude()));
        tvLng.setText(String.valueOf(mCurrentLocation.getLongitude()));
        tvUpdateTime.setText(mLastUpdateTime);

        routeOpts = new PolylineOptions().color(Color.BLUE)
                .width(3)
                .geodesic(true);
        route = mMap.addPolyline(routeOpts);
        route.setVisible(drawTrack);

        LatLng newPoint = new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude());
        List<LatLng> points = route.getPoints();
        points.add(newPoint);
        route.setPoints(points);
    }
}

I was following this question here. What I want to do is on location update, a polyline will be drawn. So basically the polyline increases as the user moves while tracking their routes. The location in the textviews are updating, but the polyline is not appearing.

Community
  • 1
  • 1
user3763216
  • 489
  • 2
  • 10
  • 29
  • 1
    It looks like you're clearing out any previously drawn Polyline each time the location changes (it looks like you never actually draw a PolyLine since you always have only one point). Take a look at the code in the question you linked to, and also the answer. The first part of your code should be called once, and then `LatLng newPoint = new LatLng()` and the following three lines of code: `getPoints()`, `add()`, and `setPoints()` should be the only code called each time the location changes. – Daniel Nugent Aug 06 '15 at 16:43
  • 1
    Oh my I am such a fool I adjusted the codes according to what you said and it worked exactly as I wanted it to! Thank you so much @DanielNugent you have a good day :-) – user3763216 Aug 06 '15 at 17:37

0 Answers0