在android中将谷歌地图缩放到以英里为单位的特定半径
我想根据我在安卓系统中的情况,将在android中将谷歌地图缩放到以英里为单位的特定半径,android,google-maps,google-maps-api-3,android-maps-v2,android-maps,Android,Google Maps,Google Maps Api 3,Android Maps V2,Android Maps,我想根据我在安卓系统中的情况,将谷歌地图缩放到以英里为单位的特定半径,比如10英里/20英里/30英里等 我需要的是从当前lat long点绘制一个特定半径(10/20/30..miles)的圆,并将地图缩放到我已绘制的具有半径的圆的特定英里数 我能指出我当前的位置,画圆圈。但我无法将地图缩放到所需的半径英里(圆圈应聚焦在屏幕上,以我当前位置为中心的指定英里数) 目前,我正在使用以下代码进行缩放: gooMap.moveCamera(CameraUpdateFactory.newLatLngZo
谷歌地图缩放到以英里为单位的特定半径,比如10英里/20英里/30英里等
我需要的是从当前lat long点绘制一个特定半径(10/20/30..miles)的圆,并将地图缩放到我已绘制的具有半径的圆的特定英里数
我能指出我当前的位置,画圆圈。但我无法将地图缩放到所需的半径英里(圆圈应聚焦在屏幕上,以我当前位置为中心的指定英里数)
目前,我正在使用以下代码进行缩放:
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不会将地图缩放到所需的英里数。但我需要把地图放大到半径。我怎样才能做到这一点。有人能帮我吗。
编辑:-添加的图像详细说明了我需要什么。
图1:-当我将半径设置为10英里时,地图应如图所示缩放。
图2当我将半径设置为50英里时,地图应如图所示缩放。
请查看地图位置的差异,以分析我需要的缩放级别。
提前感谢。刷新视图时,您需要找到屏幕上的距离。我对新的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调用中我得到了同样的解决方案,下面是一个:
// 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;
}
你所说的“缩放到欲望(原文如此)英里半径”是什么意思?缩放是一个无量纲单位。你是说你想让圆圈填满屏幕,还是说屏幕高度的50%?就目前而言,这个问题毫无意义。@NickT当我缩放屏幕时,我需要的是只在屏幕上显示圆圈。我再次问-你想要多大的圆圈?填充屏幕高度?填充屏幕宽度?占据半个屏幕?@NickT我正在画半径为指定英里(比如10英里)的圆。现在我想当地图缩放时,它应该只在屏幕上显示圆的边缘或周长。如果我将英里数增加到40英里,那么圆的半径将再次为40英里,我再次需要将地图缩放到屏幕上显示圆边的范围。不超过这个,也不低于那个。@NickT我用更多的细节编辑了这个问题。请你看看为什么你要把半径除以500?缩放级别取决于屏幕大小和dpi,所以它会在不同的设备上显示不同的结果。它给出了错误的结果。圆圈变得比屏幕大。此代码已从中获取。