Remember, THIS IS NOT A DUPLICATE QUESTION. (Please read the question carefully)
I have to check that user is inside specific area or not on Google map.
For that I have created a Polygone and I have various coordinates of that Polygone.
Now, I have to check that user's Current location is inside that Polygone or not.
For that I have created below method :
bool isUserIsInsideNagarMap(Position? currentPosition) {
final List<Point> points = <Point>[
Point(y: 72.4949812889099, x: 23.113976654405356),
Point(y: 72.49399423599242, x: 23.113700361686725),
Point(y: 72.49305009841919, x: 23.113562215114158),
Point(y: 72.49229907989502, x: 23.113522744638736),
Point(y: 72.49165534973145, x: 23.11330565681649),
Point(y: 72.49107599258423, x: 23.11302936271681),
Point(y: 72.49083995819092, x: 23.11275306804846),
Point(y: 72.49380111694336, x: 23.106536287683223),
Point(y: 72.49453067779541, x: 23.10706916585038),
Point(y: 72.49538898468018, x: 23.107592173847078),
Point(y: 72.49585032463074, x: 23.10768098632344),
Point(y: 72.49639749526978, x: 23.107868479136165),
Point(y: 72.49704122543335, x: 23.108115179806695),
Point(y: 72.49762058258057, x: 23.108312540016765),
Point(y: 72.4992513656616, x: 23.108598711806106),
Point(y: 72.5033712387085, x: 23.114272681687137),
Point(y: 72.50397205352783, x: 23.115634398774805)
];
var lat = currentPosition?.latitude.toDouble() ?? 0.0;
var lng = currentPosition?.longitude.toDouble() ?? 0.0;
final point = Point(x: lat, y: lng);
return Poly.isPointInPolygon(point, points); // true
}
You can see that I am using below method to check:
Poly.isPointInPolygon
Now, the issue is when I have passed user's current location coordinates which are there in list of points then it returns true. which is allright.
But any other coordinates of user's current location near to that coordinates in list, the method returnes false..but actually user is inside polygone.
I hope you understood the issue. So, Is there any alternative or better way for the same?