gpt4 book ai didi

java - 从一组地理点 Mapbox 中找到边界框

转载 作者:太空宇宙 更新时间:2023-11-03 11:33:18 24 4
gpt4 key购买 nike

我正在尝试从一组 GeoPoint 中找到边界框,但它没有正确缩放。我正在粘贴我用来在下面找到边界框的函数

private BoundingBox createBoundingBox(final ArrayList<LatLng> list){
double minLatitude = 90, minLongitiude = 180, maxLatitude = -90, maxLongitude = -180;
double currentLat, currentLng;
for(LatLng location : list){
currentLat = location.getLatitude();
currentLng = location.getLongitude();
minLatitude = Math.max(minLatitude, currentLat);
minLongitiude = Math.max(minLongitiude, currentLng);
maxLatitude = Math.min(maxLatitude, currentLat);
maxLongitude = Math.min(maxLongitude, currentLng);
}
return new BoundingBox(minLatitude, minLongitiude, maxLatitude - minLatitude,
maxLongitude - minLongitiude);
}

任何人都可以告诉我我在这里做错了什么。 map 缩放级别仍为 0。

最佳答案

看起来您走的路是正确的,但您的默认最小值和最大值导致了一些麻烦。请尝试以下操作:

public BoundingBox findBoundingBoxForGivenLocations(ArrayList<LatLng> coordinates)
{
double west = 0.0;
double east = 0.0;
double north = 0.0;
double south = 0.0;

for (int lc = 0; lc < coordinates.size(); lc++)
{
LatLng loc = coordinates.get(lc);
if (lc == 0)
{
north = loc.getLatitude();
south = loc.getLatitude();
west = loc.getLongitude();
east = loc.getLongitude();
}
else
{
if (loc.getLatitude() > north)
{
north = loc.getLatitude();
}
else if (loc.getLatitude() < south)
{
south = loc.getLatitude();
}
if (loc.getLongitude() < west)
{
west = loc.getLongitude();
}
else if (loc.getLongitude() > east)
{
east = loc.getLongitude();
}
}
}

// OPTIONAL - Add some extra "padding" for better map display
double padding = 0.01;
north = north + padding;
south = south - padding;
west = west - padding;
east = east + padding;

return new BoundingBox(north, east, south, west);
}

关于java - 从一组地理点 Mapbox 中找到边界框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26891776/

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