【Android】高德地图 缩放级别及像素以及地图上的点转化成屏幕上的点
/** * 调节地图到正好放置查询范围的所有点 * @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)); } }
代码片段,点击区域,显示该区域上的点
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));
文章来自:http://my.oschina.net/u/141132/blog/519254