3

我想zoomGoogle map以特定的半径(以英里为单位),比如我的条件在android中为10英里/ 20英里/ 30英里等。将Google地图缩放到以英里为单位的特定半径android

我需要的是从当前经纬度长点画出一个特定半径(10/20/30 ..英里)的圆,然后将地图缩放到特定的英里数,我已经绘制了半径为圆的圆。

我可以指出我目前的位置,画圆圈。但是我无法将地图缩放到所需的半径英里(圆圈应该以当前位置为中心,以指定的里程为焦点)。

目前我使用下面的代码来放大:

gooMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(selectedLat, selectedLong), 15)); 
        gooMap.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null); 
        Log.e("Circle Lat Long:", selectedLat + ", " + selectedLong); 
        circle.remove(); 
        circle = gooMap.addCircle(new CircleOptions() 
          .center(new LatLng(selectedLat, selectedLong)) 
          .radius(iMiles * 1609.34) // Converting Miles into Meters... 
          .strokeColor(Color.RED) 
          .strokeWidth(5)); 
        circle.isVisible(); 

我知道给缩放级别15将地图无法放大的欲望英里。但我需要将地图缩放到需要的英里半径。我怎么能实现它。任何人都可以帮助我一样。 编辑: -图片添加解释了我需要的细节。 Image_1: - 当我将我的半径设置为10英里时,地图应如图所示放大。 Image_2当我将半径设置为50英里时,地图应该如图所示放大。 请查看地图位置的区别以分析我需要的缩放级别。 Image_1 Image_2 在此先感谢。

+0

你是什么意思的“动物园做米欲望(原文如此)英里半径“?缩放是一个无量纲单位。你的意思是你想让圆圈填满屏幕,或者说屏幕高度的50%?就目前来看,这个问题毫无意义。 – NickT

+0

@NickT我需要当我缩放屏幕时,应该只在屏幕上显示圆圈。 –

+0

我再次问 - 你想要多大的圈子?填写屏幕高度?填写屏幕宽度?占据屏幕的一半? – NickT

回答

0

当视图被刷新时,你需要找到屏幕上的距离。我不是太熟悉新的API和意见,但这样的事情应该工作:

LatLngBounds bounds = map.getProjection().getVisibleRegion().latLngBounds; 
     double llNeLat = bounds.northeast.latitude; 
     double llSwLat = bounds.southwest.latitude; 
     double llNeLng = bounds.northeast.longitude; 
     double llSwLng = bounds.southwest.longitude; 
     float results[] = new float[5]; 
     Location.distanceBetween(llNeLat, llNeLng, llSwLat, llSwLng, results); 
     float radius = results[0]; 
     // radius is distance top right to bottom left on screen in metres 
     // so use maybe 3/4 of this, then conert your miles to that value 
     // in metres 

则该值添加到addCircle调用

1

我得到了相同的解决方案,这是一个:

// Zoom in, animating the camera. 
       double iMeter = iMiles * 1609.34; 
       circle.remove(); 
       circle = gooMap.addCircle(new CircleOptions() 
         .center(new LatLng(selectedLat, selectedLong)) 
         .radius(iMeter) // Converting Miles into Meters... 
         .strokeColor(Color.RED) 
         .strokeWidth(5)); 
       circle.isVisible(); 
       float currentZoomLevel = getZoomLevel(circle); 
       float animateZomm = currentZoomLevel + 5; 

       Log.e("Zoom Level:", currentZoomLevel + ""); 
       Log.e("Zoom Level Animate:", animateZomm + ""); 

       gooMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(selectedLat, selectedLong), animateZomm)); 
       gooMap.animateCamera(CameraUpdateFactory.zoomTo(currentZoomLevel), 2000, null); 
       Log.e("Circle Lat Long:", selectedLat + ", " + selectedLong); 
是计算缩放级别按设备

而我们的方法如下:

public float getZoomLevel(Circle circle) { 
     float zoomLevel=0; 
     if (circle != null){ 
      double radius = circle.getRadius(); 
      double scale = radius/500; 
      zoomLevel =(int) (16 - Math.log(scale)/Math.log(2)); 
     } 
     return zoomLevel +.5f; 
    } 
相关问题