我正在尝试从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);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。