我可以找到纬度和经度的距离(即分别为minLatitude,minLongitude,maxLatitude和maxLongitude)但是我需要样本java代码从输入纬度,经度和半径值中找到minLatitude,minLongitude,maxLatitude和maxLongitude。
以下是从lat1,long1,lat2和lang2值中找到距离的代码。
public static double distance(double lat1, double lon1, double lat2, double lon2) {
double dLat = Math.toRadians(lat2 - lat1);
double dLon = Math.toRadians(lon2 - lon1);
lat1 = Math.toRadians(lat1);
lat2 = Math.toRadians(lat2);
double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2);
double c = 2 * Math.asin(Math.sqrt(a));
return R * c;
}
答案 0 :(得分:0)
尝试类似:
/** returns minLatitude, maxLatitude, minLongitude, maxLongitude */
public double[] calculateMinMaxValues(double latitude , double longitude, double radius){
double[] res = new double[4];
res[0] /*minLatitude*/ = latitude - (radius*2)/60.0;
res[1] /*maxLatitude*/ = latitude + (radius*2)/60.0;
res[2] /*minLongitude*/ = (longitude*2)/60.0 *(Math.cos(res[0]));
res[3] /*maxLongitude*/ = (longitude*2)/60.0 *(Math.cos(res[1]));
return res;
}