Android的:在谷歌地图设置缩放级别包括所有标记点缩放、标记、级别、地图

2023-09-05 05:30:23 作者:月光太冷夜太凉

我想这样的,它包括在我的列表中所有点的android设置缩放级别的地图。我使用下面的code。

I am trying to set zoom level for Maps in android such that it includes all the points in my list. I am using following code.

int minLatitude = Integer.MAX_VALUE;
int maxLatitude = Integer.MIN_VALUE;
int minLongitude = Integer.MAX_VALUE;
int maxLongitude = Integer.MIN_VALUE;

// Find the boundaries of the item set
// item contains a list of GeoPoints
for (GeoPoint item : items) { 
    int lat = item.getLatitudeE6();
    int lon = item.getLongitudeE6();

    maxLatitude = Math.max(lat, maxLatitude);
    minLatitude = Math.min(lat, minLatitude);
    maxLongitude = Math.max(lon, maxLongitude);
    minLongitude = Math.min(lon, minLongitude);
}
objMapController.zoomToSpan(
    Math.abs(maxLatitude - minLatitude), 
    Math.abs(maxLongitude - minLongitude));

这个工程的时候。但有时某些点不显示,我需要再缩小查看这些点。请问有什么办法可以解决这个问题呢?

this works sometimes. However sometimes some points are not shown and I need to then Zoom Out to view those points. Is there any way to solve this problem?

推荐答案

我找到了自己的答案,缩放级别是正确的。我需要添加以下code在屏幕上显示的所有问题。

I found out the answer myself, the Zoom level was correct. I need to add following code to display all points on screen.

objMapController.animateTo(new GeoPoint( 
    (maxLatitude + minLatitude)/2, 
    (maxLongitude + minLongitude)/2 )); 

中心点没有属性格式排列对我产生的问题。这工作。

The center point was not propery aligned creating problem for me. This works.