Back to project page android-open-street-map.
The source code is released under:
Apache License
If you think the Android project android-open-street-map listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.android.lib.map.osm.utils; //from w w w . j ava2s .c o m import java.util.List; import com.android.lib.map.osm.GeoPoint; public class PolygonUtils { public static boolean isPointInsidePolygon(List<GeoPoint> polygon, GeoPoint g) { if (polygon == null || polygon.size() == 0) return false; int[] x = new int[polygon.size()]; int[] y = new int[polygon.size()]; int i = 0; for (GeoPoint point : polygon) { x[i] = point.getLongitudeE6(); y[i] = point.getLatitudeE6(); i++; } return isPointInsidePolygon(x, y, g.getLongitudeE6(), g.getLatitudeE6()); } public static boolean isPointInsidePolygon(int X[], int Y[], int x, int y) { int i, j; boolean c = false; for (i = 0, j = X.length-2; i < X.length-1; j = i++) { if (( ((Y[i]<=y) && (y<Y[j])) || ((Y[j]<=y) && (y<Y[i])) ) && (x < (X[j] - X[i]) * (y - Y[i]) / (Y[j] - Y[i]) + X[i])) c = !c; } return c; } }