/** * 調節地圖到正好放置查詢範圍的全部點 * @param centerLatLng 中心點 * @param range 查詢範圍(米) */ private void adjustCamera(LatLng centerLatLng,int range) { //http://www.eoeandroid.com/blog-1107295-47621.html //當前縮放級別下的比例尺 //"每像素表明" + scale + "米" float scale = g_aMap.getScalePerPixel(); //表明range(米)的像素數量 int pixel = Math.round(range / scale); //小範圍,小縮放級別(比例尺較大),有精度損失 Projection projection = g_aMap.getProjection(); //將地圖的中心點,轉換爲屏幕上的點 Point center = projection.toScreenLocation(centerLatLng); //獲取距離中心點爲pixel像素的左、右兩點(屏幕上的點 Point right = new Point(center.x + pixel, center.y); Point left = new Point(center.x - pixel, center.y); //將屏幕上的點轉換爲地圖上的點 LatLng rightLatlng = projection.fromScreenLocation(right); LatLng LeftLatlng = projection.fromScreenLocation(left); LatLngBounds bounds = LatLngBounds.builder().include(rightLatlng).include(LeftLatlng).build(); //bounds.contains(); g_aMap.getMapScreenMarkers(); //調整可視範圍 //aMap.moveCamera(CameraUpdateFactory.newLatLngBounds(LatLngBounds.builder().include(rightLatlng).include(LeftLatlng).build(), 10)); } }
代碼片斷,點擊區域,顯示該區域上的點
html
LatLng latLng = marker.getPosition(); //縮放級別 float zoom = g_aMap.getCameraPosition().zoom; //"每像素表明" + scale + "米" float scale = g_aMap.getScalePerPixel(); float range = scale * zoom; Circle circle = g_aMap.addCircle(new CircleOptions().center(latLng) .radius(range).strokeColor(getResources().getColor(R.color.color_translate)) .fillColor(getResources().getColor(R.color.color_translate)).strokeWidth(2));