2014-03-19 152 views
0

我想将Google地图的缩放级别设置为英里, 现在,我正在使用此代码,但我认为这是错误的,需要改进。Android Google Maps v2以英里为单位设置缩放级别

map.animateCamera(CameraUpdateFactory.newLatLngZoom(MYLOC, calculateZoomLevel())); 
public byte calculateZoomLevel() {  
    byte zoom = 1; 
    // if distance is in KMs 
    double E = 40075; 
    // if distance is in Miles 
    //double E = 21638; 
    zoom = (byte) Math.round(Math.log(E/nearByRadius)/Math.log(2) + 1); 
    // to avoid exeptions 
    if (zoom > 21) { 
     zoom = 21; 
    } 
    if (zoom < 1) { 
     zoom = 1; 
    } 
    Log.v(TAG, "zoom level = " + zoom); 
    return zoom; 
} 
+0

你得到了这个解决办法吗?因为我也有相同的要求。 –

回答

2

我有类似的任务,我需要显示地图中心和N公里半径。 这里是我的解决方案

private CameraUpdate getZoomForDistance(LatLng originalPosition,double distance){ 
    LatLng rightBottom = SphericalUtil.computeOffset(originalPosition,distance,135); 
    LatLng leftTop = SphericalUtil.computeOffset(originalPosition,distance,-45); 
    LatLngBounds sBounds = new LatLngBounds(new LatLng(rightBottom.latitude,leftTop.longitude),new LatLng(leftTop.latitude,rightBottom.longitude)); 
    return CameraUpdateFactory.newLatLngBounds(sBounds,0); 

} 

它使用这个库android-maps-utils 希望这将帮助你

+0

什么是computeOffset方法中的第三个参数,在computeOffset定义中它被命名为标题,但它的用途是什么? – prateek

相关问题