java – 从一组Geopoints Mapbox中找到边界框

我正在尝试从GeoPoints集合中找到边界框,但它没有正确缩放.我正在粘贴我用来找到下面边界框的功能

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);
}

任何人都可以告诉我这里我做错了什么.地图缩放级别仍为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 android


下一篇:c# – 无法使用Mapbox“创建上传”API来上传数据文件