gpt4 book ai didi

java - 如何在谷歌地图中的两点范围之间进行选择

转载 作者:行者123 更新时间:2023-12-01 05:19:33 24 4
gpt4 key购买 nike

如何在谷歌地图中的两个点范围之间进行选择。例如:50m 或 100m

我使用此代码来计算距离。

    public class DistanceCalculator {

public static final double Radius = 6378.1;

public double CalculationByDistance(GeoPoint startp, GeoPoint endp) {
double lat1 = startp.getLatitudeE6()/1E6;
double lat2 = endp.getLatitudeE6()/1E6;
double lon1 = startp.getLongitudeE6()/1E6;
double lon2 = endp.getLongitudeE6()/1E6;
double dLat = Math.toRadians(lat2-lat1);
double dLon = Math.toRadians(lon2-lon1);
double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
Math.sin(dLon/2) * Math.sin(dLon/2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
return Radius * c;

}
}

最佳答案

MapViewController有一个名为zoomToSpan(int, int)的方法。因此,您所需要做的就是找到两点的中心,然后缩放到它们之间的跨度。这是文档:

public void zoomToSpan(int latSpanE6,int lonSpanE6)

Attempts to adjust the zoom of the map so that the given span of latitude and longitude will be displayed. Because the zoom can only achieve discrete levels, and because the aspect ratio of the map may not match the ratio given, the quality of the fit may vary. The only thing we guarantee is that, after the zoom, at least one of the new latitude or the new longitude will be within a factor of 2 from the corresponding parameter.

关于java - 如何在谷歌地图中的两点范围之间进行选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10637471/

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