开发者

How to test if a point inside area with lat/lon and radius using Java?

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 r开发者_开发问答eturn true, false otherwise.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜