开发者

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

开发者 https://www.devze.com 2023-03-16 19:23 出处:网络
I\'ve to write a method that has the following signature public class Position { double longitude; double latitude;

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

精彩评论

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

关注公众号