Click here to Skip to main content
14,325,129 members
Rate this:
Please Sign up or sign in to vote.
Hi there,
I am using the Google Location Services API on Android to periodically save a latitude/longitude they were at. I am trying to create a polygon around these points to create a route of where they have been. I want the route to take into the location accuracy for each of the points, so instead of a line it will look like a snake that expands and shrinks as the GPS accuracy changes.

This is something close to what I want, however, it is a polyline with a standard thickness throughout.

At a later time, I want to be able to validate if the user has returned inside this polygon.

Thanks in advance for any help!
Ronan

What I have tried:

I am using location.getAccuracy() to determine the accuracy of the polled location and my aim is to include a radius around the point based on this. This accuracy is then used to create a diamond of four points. Although this accurately shows for one location, when multiple locations are added, the polygon looks very wrong with points intersecting each other.

I thought about drawing one big polygon around all the locations but this wouldn't work as I would end up with an area instead of a route, the polygon wouldn't show accurately where the user actually travelled.

How I am generating the polygon points at the moment:
List<LatLng> points = new ArrayList<LatLng>();

for (Location location : locations) {
    float accuracy = location.getAccuracy();
    System.out.println(accuracy);
    points.add(SphericalUtil.computeOffset(new LatLng(location.getLatitude(), location.getLongitude()), accuracy, 0));
    points.add(SphericalUtil.computeOffset(new LatLng(location.getLatitude(), location.getLongitude()), accuracy, 90));
    points.add(SphericalUtil.computeOffset(new LatLng(location.getLatitude(), location.getLongitude()), accuracy, 180));
    points.add(SphericalUtil.computeOffset(new LatLng(location.getLatitude(), location.getLongitude()), accuracy, 270));
}



How I draw the polygon onto the map:
PolygonOptions polygonOptions = new PolygonOptions();

	for (LatLng latLng : route.getPolygonPoints()) {
		polygonOptions.add(latLng);
	}

	mMap.clear();
	Polygon polygon = mMap.addPolygon(polygonOptions.strokeColor(Color.argb(255, 49, 101, 187)).fillColor(Color.argb(100, 49, 101, 187)));
Posted
Updated 15-Oct-16 10:27am
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100