gpt4 book ai didi

java - 根据给定的纬度、经度和半径值在 Java 中查找最小和最大纬度和经度

转载 作者:行者123 更新时间:2023-12-03 23:16:22 25 4
gpt4 key购买 nike

我可以从纬度和经度(即分别为 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;
}

最佳答案

尝试类似的东西:

/** 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;
}

关于java - 根据给定的纬度、经度和半径值在 Java 中查找最小和最大纬度和经度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22929748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com