【问题标题】:Android Google Maps v2 Set Zoom Level in MilesAndroid Google Maps v2 以英里为单位设置缩放级别
【发布时间】:2014-03-19 09:30:11
【问题描述】:

我想以英里为单位设置谷歌地图的缩放级别, 现在,我正在使用这段代码,但我认为它是错误的,需要改进。

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;
}

【问题讨论】:

  • 您找到解决方案了吗?因为我也有同样的要求..

标签: android google-maps google-maps-api-2


【解决方案1】:

我有类似的任务,我需要显示具有中心和 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 希望对你有帮助

【讨论】:

  • computeOffset 方法中的第三个参数是什么,在 computeOffset 定义中它被命名为标题,但它是它的目的?
【解决方案2】:

基于@alexandr 响应

fun newLatLngOffset(center: LatLng, dist: Int): CameraUpdate {
    return CameraUpdateFactory.newLatLngBounds(
        LatLngBounds.Builder()
            .include(SphericalUtil.computeOffset(center, dist.toDouble(), 0.0))
            .include(SphericalUtil.computeOffset(center, dist.toDouble(), 90.0))
            .include(SphericalUtil.computeOffset(center, dist.toDouble(), 180.0))
            .include(SphericalUtil.computeOffset(center, dist.toDouble(), 270.0))
            .build(), 0
    )
}

主要区别在于他解的圈子是外接的,我是内接的

【讨论】:

    猜你喜欢
    • 2012-12-05
    • 2013-06-04
    • 1970-01-01
    • 2013-08-27
    • 2012-12-18
    • 1970-01-01
    • 2014-01-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多