Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

identify which is the polygon from latitude and longitude

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?

like image 207
Sudha Avatar asked Mar 27 '13 05:03

Sudha


People also ask

What is a location polygon?

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.

How to find Lat and long coordinates?

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...

What is latitude and longitude in GPS?

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

What is latlatitude and longitude?

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.


1 Answers

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
        } 
    }
like image 124
Sudha Avatar answered Sep 29 '22 08:09

Sudha