我有 3 组坐标
2 和 3 是正方形/长方形的对角线。我必须找出给定的坐标(1)是否位于 2&3 之内。
之前有人提出过同样的问题,但没有给出答案。 重复问题
我得到了我正在寻找的解决方案。从这里得到解决方案
/*
* top: north latitude of bounding box.
* left: left longitude of bounding box (western bound).
* bottom: south latitude of the bounding box.
* right: right longitude of bounding box (eastern bound).
* latitude: latitude of the point to check.
* longitude: longitude of the point to check.
*/
boolean isBounded(double top, double left,
double bottom, double right,
double latitude, double longitude){
/* Check latitude bounds first. */
if(top >= latitude && latitude >= bottom){
/* If your bounding box doesn't wrap
the date line the value
must be between the bounds.
If your bounding box does wrap the
date line it only needs to be
higher than the left bound or
lower than the right bound. */
if(left <= right && left <= longitude && longitude <= right){
return true;
} else if(left > right && (left <= longitude || longitude <= right)) {
return true;
}
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2815 次 |
最近记录: |