自动大小在Java上的谷歌地图的缩放? (取决于Android的屏幕分辨率)缩放、大小、屏幕分辨率、地图

2023-09-07 16:02:47 作者:瑾色长安

我得给他们展示与标记在地图上2 GeoPoints。

I've got 2 GeoPoints given to show them on the map with markers.

我怎样才能为MapController最佳缩放级别,以便集中两个点中间,也让他们在地图上。

How can I get the optimum zoom level for the MapController in order to focus the middle of both points, but also have them on the map.

整个事情应该在不同的屏幕分辨率运行。

The whole thing should work at different screen resolutions.

推荐答案

您可以使用做到这一点的MapView的 MapController 。你得到使用MapController MapView.getController(),那么你可以尝试设置使用MapController.zoomToSpan正确变焦()。我也倾向于使用ItemizedOverlay的getLatSpanE6()和getLonSpanE6(),使这个简单。举个例子:

You can do this using the MapView's MapController. You get the MapController using MapView.getController(), then you can attempt to set the correct zoom using MapController.zoomToSpan(). I also tend to use ItemizedOverlay's getLatSpanE6() and getLonSpanE6() to make this simpler. An example:

MapView map = (MapView) findViewById(R.id.Map);
MapController mc = map.getController();
mc.zoomToSpan(overlay.getLatSpanE6(), overlay.getLonSpanE6());

要注意他们的警告是非常重要的:

It is important to note their caveat:

由于变焦只能达到  离散电平,并且因为  地图的纵横比可能不匹配  给定的比例,的质量  适合可能会有所不同。我们唯一  保证的是,在变焦之后,在  新纬度至少一种或  新经度将是一个因素内  2从相应的参数

Because the zoom can only achieve discrete levels, and because the aspect ratio of the map may not match the ratio given, the quality of the fit may vary. The only thing we guarantee is that, after the zoom, at least one of the new latitude or the new longitude will be within a factor of 2 from the corresponding parameter.

编辑:为了也得到了地图缩放在正确的位置,你必须使用MapController.setCenter()

In order to also get the map to zoom on the correct place, you have to use MapController.setCenter().