How to test if a point inside area with lat/lon an

2019-04-10 20:41发布

问题:

I've to write a method that has the following signature

public class Position {
double longitude;
double latitude;
}

boolean isInsideTheArea(Position center, double radius, Position point);

So if point is inside the area that has the center as its center and radius as its radius in miles, this should return true, false otherwise.

回答1:

Use the Haversine formula to compute the distance between center and point. If that distance is greater than radius, return false; otherwise return true.

Pseudocode:

def haversineDistance(a, b):
    # snip...
    return foo

def isInsideTheArea (center, radius, point):
    return haversineDistance(center, point) <= radius


回答2:

hope this helps there are also some implementation examples http://en.wikipedia.org/wiki/Haversine_formula