locationIndexOnEdgeOrPath static method
Implementation
static int locationIndexOnEdgeOrPath(
LatLng point, List<LatLng> poly,LatLngBounds bounds) {
bool closed = false;
try {
if (poly[0] == poly[poly.length-1]) closed = true;
} catch (e) {}
int size = poly.length;
if (size == 0) {
return -1;
}
double tolerance = DistanceAlgo.getDistanceBetween2Points(bounds.northeast, bounds.southwest)*(0.01) / GeoUtil.EARTH_RADIUS;
num havTolerance = MathUtil.hav(tolerance);
num lat3 = MathUtil.toRadians(point.latitude);
num lng3 = MathUtil.toRadians(point.longitude);
LatLng prev = poly[closed ? size - 1 : 0];
num lat1 = MathUtil.toRadians(prev.latitude);
num lng1 = MathUtil.toRadians(prev.longitude);
int idx = 0;
for (LatLng point2 in poly) {
num lat2 = MathUtil.toRadians(point2.latitude);
num lng2 = MathUtil.toRadians(point2.longitude);
if (GeoUtil.isOnSegmentGC(lat1, lng1, lat2, lng2, lat3, lng3, havTolerance)) {
return max(0, idx - 1);
}
lat1 = lat2;
lng1 = lng2;
idx++;
}
return -1;
}