如何放大一个MapView类,因此始终包括两个geopoints? [英] How to zoom a MapView so it always includes two geopoints?

查看:96
本文介绍了如何放大一个MapView类,因此始终包括两个geopoints?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个地理点的变化间歇性,并且希望的MapView来调整和转换,以确保这两点始终可见。我可以很容易地重新中心在两者之间的点中途的地图,但是我怎么设置缩放级别,以确保我的两点是可见的?

I have two geo points that vary intermittently, and want the MapView to resize and translate to make sure both points are always visible. I can easily re-centre the map on the point mid-way between the two, but how do I set the zoom level to ensure my two points are visible?

推荐答案

试试这个,看看:

double latitudeSpan = Math.round(Math.abs(firstLat - 
                secLat));
double longitudeSpan = Math.round(Math.abs(firstLong - 
                secLong));

double currentLatitudeSpan = (double)mapView.getLatitudeSpan();
double currentLongitudeSpan = (double)mapView.getLongitudeSpan();

double ratio = currentLongitudeSpan/currentLatitudeSpan;
if(longitudeSpan < (double)(latitudeSpan+2E7) * ratio){
    longitudeSpan = ((double)(latitudeSpan+2E7) * ratio);
}

mapController.zoomToSpan((int)(latitudeSpan*2), (int)(longitudeSpan*2));                
mapView.invalidate();

这篇关于如何放大一个MapView类,因此始终包括两个geopoints?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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