void main() {
bool isPtInPoly(double aLon, double aLat, List points) {
int iSum = 0;
int iCount = points.length;
if (iCount < 3) {
return false;
}
int cc = 0;
for (int i = 0; i < iCount; i++) {
double pLon1 = double.parse(points[i]["lon"]);
double pLat1 = double.parse(points[i]["lat"]);
double pLon2 = 0.0;
double pLat2 = 0.0;
if (i == (iCount - 1)) {
pLon2 = double.parse(points[0]["lon"]);
pLat2 = double.parse(points[0]["lat"]);
} else {
pLon2 = double.parse(points[i+1]["lon"]);
pLat2 = double.parse(points[i+1]["lat"]);
}
if (((aLat >= pLat1) && (aLat < pLat2)) || ((aLat >= pLat2) && (aLat < pLat1))) {
if ((pLat1 - pLat2).abs() > 0) {
double pLon = pLon1 - ((pLon1 - pLon2) * (pLat1 - aLat)) / (pLat1 - pLat2);
if (pLon < aLon) {
iSum++;
}
}
}
}
print('iSum=$iSum');
if (iSum % 2 != 0) {
return true;
}
return false;
}
test(){
String path = '104.999066,25.405241;104.947906,25.372217;104.925512,25.353427;104.950658,25.337585;104.938689,25.301009;104.91765,25.311038;104.907344,25.296518;104.906417,25.315007;104.897035,25.320785;104.884742,25.326306;104.893944,25.335009;104.889125,25.346041;104.892862,25.35131;104.893543,25.360192;104.889065,25.368307;104.87591,25.375487;104.857958,25.381895;104.851341,25.401385;104.87268,25.460918;104.902155,25.49904;104.902809,25.557038;104.87897,25.571202;104.863143,25.614407;104.887238,25.643188;104.909212,25.688922;104.893182,25.723173;104.870101,25.774915;104.884981,25.82233;104.911071,25.846929;104.947185,25.866956;104.950122,25.914796;104.932684,25.93441;104.940085,25.974696;104.957849,26.038648;104.97087,26.055494;104.980419,26.066747;105.010101,26.098628;105.004531,26.133038;105.052085,26.172592;105.065845,26.162528;105.078244,26.160672;105.104352,26.164629;105.129225,26.158422;105.138633,26.150609;105.129609,26.1526;105.119131,26.159808;105.108367,26.130394;105.094206,26.092878;105.053104,26.056173;105.018685,26.008927;105.023173,25.968666;105.04022,25.970624;105.036902,25.954858;105.071591,25.956859;105.085519,25.955802;105.08695,25.949879;105.11204,25.947027;105.125584,25.927914;105.123533,25.889199;105.127185,25.83905;105.091774,25.805557;105.107484,25.738182;105.102834,25.709525;105.079388,25.704898;105.053334,25.674708;105.050217,25.659717;105.074681,25.654425;105.071495,25.632607;105.073549,25.603965;105.091727,25.57936;105.096438,25.568166;105.121369,25.539944;105.092732,25.516962;105.069052,25.50134;105.02564,25.45538';
List points = [];
List list = path.split(';');
for(String p in list){
List arr = p.split(',');
points.add({"lon": arr[0], "lat": arr[1]});
}
bool rs = isPtInPoly(104.952912, 25.783916, points);
print('isPtInPoly=$rs');
}
test();
}