I have a map drawn using leaflet.js. If I give longitude and latitude value as input Can I identify the polygon? Can I get a client side script for this?
A location polygon is an object that represents a place, point of interest, or location in the real world. Polygons are usually represented by the coordinates of their vertices. A polygon may have any number of vertices and any number of edges. The coordinates of the vertices are typically represented using WGS84 latitude and longitude pairs.
Get Latitude and Longitude. To make a search, use the name of a place, city, state, or address, or click the location on the map to find lat long coordinates. Add the country code for better results. Looking for the lat long, please wait...
Latitude and longitude is to used to find the latitude and longitude of your current location. Latitude and Longitude are the two angles that define the precision location of a point on earth or the GPS coordinates. GPS Coordinates
Latitude and longitude is to used to find the latitude and longitude of your current location. Latitude and Longitude are the two angles that define the precision location of a point on earth or the GPS coordinates.
Got an answer as follows :
//This is based on 'point in polygon algorithm'
function getPoint () {
float x=-89.82421875; //x and y represents the lat and lng values
float y= 40.18307014852533;
var a = boundaries; //the coordinates used to draw the map
for (i = 0; i < a.features.length; i++) {
PointInPolygon(x,y, a.features[i].geometry.coordinates[0], i);
}
};
function PointInPolygon(pointX, pointY, _vertices, number) {
var j = _vertices.length - 1;
var oddNodes = false;
var polyX, polyY,polyXJ,polyYJ;
for (var i = 0; i < _vertices.length; i++) {
polyY = parseFloat(_vertices[i].toString().split(",")[1]);
polyX = parseFloat(_vertices[i].toString().split(",")[0]);
polyXJ = parseFloat(_vertices[j].toString().split(",")[0]);
polyYJ = parseFloat(_vertices[j].toString().split(",")[1]);
if (polyY < pointY && polyYJ >= pointY ||
polyYJ < pointY && polyY >= pointY) {
if (polyX +
(pointY - polyY) / (polyYJ - polyY) * (polyXJ - polyX) < pointX)
{
oddNodes = !oddNodes;
}
}
j = i;
}
if (oddNodes == true) {
map._layers[number+1].fire('click'); //fire the map click event
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With