Hello Friends,
Today, I am sharing my code which helps you in calculating Centroid of a polygone
and show it on Google Map.
Hope, Its helps someone.
Enjoy Coding.... :)
Today, I am sharing my code which helps you in calculating Centroid of a polygone
and show it on Google Map.
public static LatLng getCentroid(ArrayList<IGeoPoint> points) { double[] centroid = { 0.0, 0.0 }; for (int i = 0; i < points.size(); i++) { centroid[0] += points.get(i).getLatitude(); centroid[1] += points.get(i).getLongitude(); } int totalPoints = points.size(); centroid[0] = centroid[0] / totalPoints; centroid[1] = centroid[1] / totalPoints; return new LatLng(centroid[0], centroid[1]); }
Hope, Its helps someone.
Enjoy Coding.... :)
Hi, what type of object is polypoints??
ReplyDeleteI ask you that because it don't work with my polygon. That's my code:
poligonoOptions = new PolygonOptions()
.add(new LatLng(37.379749, -6.007010))
.add(new LatLng(37.381335, -6.008748))
.add(new LatLng(37.382170, -6.007579))
.add(new LatLng(37.380619, -6.005868))
.add(new LatLng(37.379749, -6.007010));
Hello Alejandro,
ReplyDeleteI just update the code , its "IGeoPoint" not ploypoints.
And its contain the latitude and longitude.