Forum Moderators: phranque
I was wondering how I can determine if a point using it's longitude and latitude, falls within a range of other points using their longitude and latitude.
Math and I have a great understanding, I don't harm it and it doesn't harm me so I am not really sure how to go about figuring this out.
Say my point is at: -87.700382,41.997543
And the range I want to compare it to is this:
87.6739609156651,41.9615320224265
87.6741899156652,41.9615270224267
87.6745139156657,41.9615200224266
87.6751639156662,41.9615030224266
87.6752379156663,41.9615010224266
I'm just using this as an example, I'm not entirely sure if this range would form much of a shape but I just wanted to show what I am doing. If anyone could give me an idea of what to do, I would really appreciate it.
If you are still in the shape, then the next stage is to find the points which are nearest vertically and horizontally. From that your problem is reduced to either a triangle or a quadrilateral - both of these are much easier to solve than an abstract polygon.
If you aren't really very fussy about accuracy, just do the exclusion part at the beginning and leave it at that.
if(sqrt((69.1 * (latitude1 - latitude2)) * (69.1 * (latitude1 - latitude2)) + (53.0 * (longitude1 - longitude2)) * (53.0 * (longitude1 - longitude2))) < 0.5) { do some stuff } else { don't do some stuff }
I found a couple of semi-solutions. One was a php solution where it takes points and compares them, however it doesn't seem to work for latitude and longitude in that I can't compare 1 point against multiple ones.
The other solution I found uses MS Virtual Earth. It takes all my points and makes a polygon, then if I click inside the polygon in the map, an alert box returns true, if I click outside, it returns false.
This one in theory work great however a JavaScript master, I am not. I am going to take this to the Javascript board and see if there is a way for me to instead give the point and let it do it's thing and just write to the screen if it's true or not.
Thanks for everyone's help, I really appreciate it.
several websites can verify distances you calculate via online form. counties, cities and closer can also be correlated to lat/lon pairs to use in calcs. for counties we get one pair which is the centroid of the county. street level DBs can be bought with address lat/lon
You do need to be aware when the shortest distance between the two points passes through the Equator or passes through either 0 degrees E/W or 180 degrees E/W longitude as you'll need to cater for that.
Also, you'll need to decide which Earth Model you want to use... assume a prefect sphere with which radius distance (several are quoted), or use the corrections for an oblate spheroid (which is what the Earth actually is)?