JSFiddle - React, Tailwind, and code Playground
HTML
<div id="output"></div>
JavaScript
polygone= [
[43.163834,-84.134153],
[43.163834,-83.420042],
[42.790073,-82.975095],
[42.519397,-82.876218],
[42.206868,-83.112424],
[42.076528,-83.200315],
[42.117288,-83.524412],
[42.239411,-84.079221],
[42.652862,-84.227537],
[42.914912,-84.255002],
[43.127763,-84.145139],
[43.161783,-84.134016]
]
function isPointInPoly(point, vs) {
var x = point[0], y = point[1];
var inside = false;
for (var i = 0, j = vs.length - 1; i < vs.length; j = i++) {
var xi = vs[i][0], yi = vs[i][1];
var xj = vs[j][0], yj = vs[j][1];
var intersect = ((yi > y) != (yj > y))
&& (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
if (intersect) inside = !inside;
}
return inside;
};
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
console.log(`Latitude: ${latitude}, Longitude: ${longitude}`);
});
} else {
console.log("Geolocation is not supported by this browser.");
}
//if(isPointInPoly([ $latitude, $longitude ], polygone) === true) {
// $("#output").html('Yup');
//} else {
// $("#output").html('Nope');
//}
jQuery(window).ready(function () {
$("#output").html(isPointInPoly([ 42.9948928, -83.689472 ], polygone));
});
console.log(isPointInPoly([42.9948928, -83.689472], polygone));