I would not use a centroid (or a barycenter, or a center of mass in the case of a uniform density) if you need to show a figure (figure, region) in the layout. What I really need to center the figure in the layout is the maximum and minimum of all coordinates to show each point.
ArrayList<GeoPoint> track; public GeoPoint CenterMap() { double longitude = 0; double latitude = 0; double maxlat = 0, minlat = 0, maxlon = 0, minlon = 0; int i = 0; for (GeoPoint p : track) { latitude = p.getLatitude(); longitude = p.getLongitude(); if (i == 0) { maxlat = latitude; minlat = latitude; maxlon = longitude; minlon = longitude; } else { if (maxlat < latitude) maxlat = latitude; if (minlat > latitude) minlat = latitude; if (maxlon < longitude) maxlon = longitude; if (minlon > longitude) minlon = longitude; } i++; } latitude = (maxlat + minlat) / 2; longitude = (maxlon + minlon) / 2; return new GeoPoint(latitude, longitude); }
Zanna
source share