gpt4 book ai didi

android - 将 LatLngBounds 缩小 5%

转载 作者:行者123 更新时间:2023-11-29 19:16:11 26 4
gpt4 key购买 nike

好吧,在阅读了 Antonio 的评论后,我在我的代码中接受了这个。现在,无论我提交的百分比是多少,它仍然认为我的对象在边界框之外。

My Position 是传入的marker。

LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds;
LatLngBounds newBounds = reduceBy(bounds, 0.05d);

if(newBounds.contains(myPosition.getPosition())) {
//If the item is within the the bounds of the screen
} else{
//If the marker is off screen
zoomLevel -= 1;}
}
return zoomLevel;
}


public LatLngBounds reduceBy(LatLngBounds bounds, double percentage) {
double distance = SphericalUtil.computeDistanceBetween(bounds.northeast, bounds.southwest);
double reduced = distance * percentage;

double headingNESW = SphericalUtil.computeHeading(bounds.northeast, bounds.southwest);
LatLng newNE = SphericalUtil.computeOffset(bounds.northeast, reduced/2d, headingNESW);

double headingSWNE = SphericalUtil.computeHeading(bounds.southwest, bounds.northeast);
LatLng newSW = SphericalUtil.computeOffset(bounds.southwest, reduced/2d, headingSWNE);

return LatLngBounds.builder().include(newNE).include(newSW).build();
}

}

我已经设置了所有的缩放级别,但有时我会遇到像这样的点,它仍然在边界内,只是标记不在屏幕上。我想要一个稍微小一点的边界框来检测这一点,然后仅在这些情况下缩小一个级别。

enter image description here

最佳答案

您可以使用 Google Maps API Utility Library 中的 SphericalUtil 类进行计算:

public LatLngBounds reduceBy(LatLngBounds bounds, double percentage) {
double distance = SphericalUtil.computeDistanceBetween(bounds.northeast, bounds.southwest);
double reduced = distance * percentage;

double headingNESW = SphericalUtil.computeHeading(bounds.northeast, bounds.southwest);
LatLng newNE = SphericalUtil.computeOffset(bounds.northeast, reduced/2d, headingNESW);

double headingSWNE = SphericalUtil.computeHeading(bounds.southwest, bounds.northeast);
LatLng newSW = SphericalUtil.computeOffset(bounds.southwest, reduced/2d, headingSWNE);

return LatLngBounds.builder().include(newNE).include(newSW).build();
}

要将边界缩小 5%(对角线),您可以:

LatLngBounds newBounds = reduceBy(bounds, 0.05d);

关于android - 将 LatLngBounds 缩小 5%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43458546/

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