Android的图形页面自动-setting变焦,直到所有ItemizedOverlay的可见 [英] Android MapView -setting zoom automatically until all ItemizedOverlay's are visible

查看:84
本文介绍了Android的图形页面自动-setting变焦,直到所有ItemizedOverlay的可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

硬编码setZoom()内的onCreate()感觉非常陈旧,我想由最初具有的MapView设置缩放,直到所有GeoPoints / OverlayItems都显示在地图上,以提升用户体验。

hard-coding the setZoom() within onCreate() feels very antiquated and I'd like to enhance the user experience by initially having the MapView set the zoom until all GeoPoints / OverlayItems are visible on the map.

如何才能做到这一点自动神奇?

How can this be done auto-magically?

推荐答案

有点像这样

int minLat = Integer.MAX_VALUE;
int maxLat = Integer.MIN_VALUE;
int minLon = Integer.MAX_VALUE;
int maxLon = Integer.MIN_VALUE;

for (GeoPoint item : items) 
{ 

      int lat = item.getLatitudeE6();
      int lon = item.getLongitudeE6();

      maxLat = Math.max(lat, maxLat);
      minLat = Math.min(lat, minLat);
      maxLon = Math.max(lon, maxLon);
      minLon = Math.min(lon, minLon);
 }

mapController.zoomToSpan(Math.abs(maxLat - minLat), Math.abs(maxLon - minLon));
mapController.animateTo(new GeoPoint( (maxLat + minLat)/2, 
(maxLon + minLon)/2 )); 


编辑:瑞恩给了一个很好的建议:把一个填充,这样一些点不撒谎的边缘(!感谢瑞安)


edit: Ryan gave a nice suggestion : to put a padding so that some of the point don't lie on the edges (thanks Ryan!)

double fitFactor = 1.5;
mapController.zoomToSpan((int) (Math.abs(maxLat - minLat) * fitFactor), (int)(Math.abs(maxLon - minLon) * fitFactor));

这篇关于Android的图形页面自动-setting变焦,直到所有ItemizedOverlay的可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆