只需要获取对角经纬度即可
/**
* 判断是否在区域内
*
* @param latitue
* @param longitude
* @param areaLatitude1
* @param areaLatitude2
* @param areaLongitude1
* @param areaLongitude2
* @return
*/
public static boolean isInArea(Double latitue, Double longitude, Double areaLatitude1, Double areaLatitude2, Double areaLongitude1, Double areaLongitude2) {
if (isInRange(latitue, areaLatitude1, areaLatitude2)) {//如果在纬度的范围内
if (areaLongitude1 * areaLongitude2 > 0) {//如果都在东半球或者都在西半球
if (isInRange(longitude, areaLongitude1, areaLongitude2)) {
return true;
} else {
return false;
}
} else {//如果一个在东半球,一个在西半球
if (Math.abs(areaLongitude1) + Math.abs(areaLongitude2) < 180.0) {//如果跨越0度经线在半圆的范围内
if (isInRange(longitude, areaLongitude1, areaLongitude2)) {
return true;
} else {
return false;
}
} else {//如果跨越180度经线在半圆范围内
double left = Math.max(areaLongitude1, areaLongitude2);//东半球的经度范围left-180
double right = Math.min(areaLongitude1, areaLongitude2);//西半球的经度范围right-(-180)
if (isInRange(longitude, left, 180.0) || isInRange(longitude, right, -180.0)) {
return true;
} else {
return false;
}
}
}
} else {
return false;
}
}
private static boolean isInRange(Double point, Double left, Double right) {
if (point >= Math.min(left, right) && point <= Math.max(left, right)) {
return true;
} else {
return false;
}
}