Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Polyline - Adding point by point

I'm currently having a map, and each 10 meters I use LocationListener to refresh my location and get the new Latitude and Longitude. Now I wish that the route the user is taking will be displayed with a red line. So everytime the OnLocationChange() from LocationListener class is called, I want to update the map with a line between the last location and the new location.

So far I've added the following:

private void initializeDraw() {
    lineOptions = new PolylineOptions().width(5).color(Color.RED);
    lineRoute = workoutMap.addPolyline(lineOptions);
}

during the OnLocationChanged I call this:

drawTrail();

now what should I insert into this function so that each time it adds the newly attained location as a point and draws a line from the last to the new point.

Thanks

like image 743
rockyl Avatar asked Jun 17 '13 21:06

rockyl


People also ask

What is a Polyline in Android?

A polyline is a list of points, where line segments are drawn between consecutive points. A polyline has the following properties: Methods in this class must be called on the Android UI thread. If not, an IllegalStateException will be thrown at runtime.

How do I add a polyline to a Google map?

Call GoogleMap.addPolyline () to add the polyline to the map. Set the polyline's clickable option to true if you want to handle click events on the polyline. There's more about event handling later in this tutorial.

What are polylines and circles in Android maps?

You've built an Android app containing a Google map, with polygons to represent areas on the map and polylines to represent routes or other connections between locations. You've also learned how to use the Maps SDK for Android . Learn about the Circle object. Circles are similar to polygons but have properties that reflect the shape of a circle.

What is a Polyline in AutoCAD?

A Polyline is a series of connected line segments. Polylines are useful to represent routes, paths, or other connections between locations on the map. Create a PolylineOptions object and add points to it. Each point represents a location on the map, which you define with a LatLng object containing latitude and longitude values.


1 Answers

First translate Location into LatLng:

LatLng newPoint = new LatLng(location.getLatitude(), location.getLongitude());

Then add a point to existing list of points:

List<LatLng> points = lineRoute.getPoints();
points.add(newPoint);
lineRoute.setPoints(points);
like image 132
MaciejGórski Avatar answered Sep 28 '22 00:09

MaciejGórski