Pra*_*ela 4 android google-maps google-maps-api-3 android-maps android-maps-v2
我想zoom
在Google map
在英里的半径特定比如说10英里/ 20英里/ 30英里等按我的条件在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();
Run Code Online (Sandbox Code Playgroud)
我知道将缩放级别设置为 15 不会将地图缩放到所需的英里数。但我需要缩放地图以达到英里半径。我怎样才能实现它。任何人都可以帮助我。
编辑:-添加的图像详细解释了我需要的内容。Image_1:- 当我将半径设置为 10 英里时,地图应如图所示缩放。Image_2 当我将半径设置为 50 英里时,地图应如图所示缩放。请查看地图位置的差异以分析我需要的缩放级别。
提前致谢。
我得到了同样的解决方案,这是一个:
// 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);
Run Code Online (Sandbox Code Playgroud)
我们根据设备计算缩放级别的方法如下:
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;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8216 次 |
最近记录: |