我曾经在我的项目库名mapviewballoon mapviewballon 。
当我设置20,30或多个引脚上缩放到中央的最后一针的不同位置,我想要的是缩放级别是这样的,它显示在地图视图所有引脚地图。
我怎么能解决这个问题,或计算正确的缩放,我目前给14。
做的事情如下:
OverlayItem overlayItem = NULL;的GeoPoint点= NULL;的for(int i = 0; I< nearbyObjMapList.size();我++){ 如果(nearbyObjMapList.get㈠.latitude.equals(0)及!&放大器;!nearbyObjMapList.get(ⅰ).longitude.equals(0)){ 纬度= Float.parseFloat(nearbyObjMapList.get(我).latitude); 经度= Float.parseFloat(nearbyObjMapList.get(我).longitude); 点=新的GeoPoint((int)的(纬度* 1E6),(INT)(经度* 1E6)); overlayItem =新OverlayItem(点,nearbyObjMapList.get(I).venue_name,); itemizedOverlay.addOverlay(overlayItem); } }如果(thisState == NULL){ 最后MapController MC = mapView.getController(); mc.animateTo(点); mc.setZoom(14); }其他{ //例如恢复覆盖的聚焦状态 INT重点; 聚焦= thisState.getInt(focused_1,-1); 如果(聚焦> = 0){ itemizedOverlay.setFocus(itemizedOverlay.getItem(聚焦)); } 聚焦= thisState.getInt(focused_2,-1); 如果(聚焦> = 0){ temizedOverlay2.setFocus(itemizedOverlay2.getItem(聚焦)); } }解决方案
不要使用setZoom(),它始终是更好地使用zoomToSpan当你有很多引脚指出。你以后在下面添加code你的循环,这对我来说完美的作品。
如果(nearbyObjMapList.length!= 0) { mapOverlays.add(itemizedoverlay); //显示所有物品叠加 itemizedoverlay.populateNow(); //调节缩放比例,这样就可以看到地图上的所有标记 。mv.getController()zoomToSpan(Math.abs(minLat - maxLat),Math.abs(闽龙 - MAXLONG)); //显示在地图的中心 mc.animateTo(新的GeoPoint((maxLat + minLat)/ 2,(MAXLONG +闽龙)/ 2)); } mv.postInvalidate();I used a library name mapviewballoon in my project mapviewballon .
when I set 20,30 or more pins the map on different locations it zooms to the last pin in the center, what I want is that the zoom level is such that it show up all pins in the map view.
how can I solve that, or calculate the right zoom, currently I given 14.
doing things as follow:
OverlayItem overlayItem = null; GeoPoint point = null; for (int i = 0; i < nearbyObjMapList.size(); i++) { if (!nearbyObjMapList.get(i).latitude.equals("0") && !nearbyObjMapList.get(i).longitude.equals("0")) { Latitude = Float.parseFloat(nearbyObjMapList.get(i).latitude); Longitude = Float.parseFloat(nearbyObjMapList.get(i).longitude); point = new GeoPoint((int)(Latitude*1E6),(int)(Longitude*1E6)); overlayItem = new OverlayItem(point, nearbyObjMapList.get(i).venue_name, ""); itemizedOverlay.addOverlay(overlayItem); } } if (thisState == null) { final MapController mc = mapView.getController(); mc.animateTo(point); mc.setZoom(14); } else { // example restoring focused state of overlays int focused; focused = thisState.getInt("focused_1", -1); if (focused >= 0) { itemizedOverlay.setFocus(itemizedOverlay.getItem(focused)); } focused = thisState.getInt("focused_2", -1); if (focused >= 0) { temizedOverlay2.setFocus(itemizedOverlay2.getItem(focused)); } }解决方案
Don't use setZoom() and it is always better to use zoomToSpan when you have many pins to be pointed. You add below code after your for loop, which works perfect for me.
if(nearbyObjMapList.length!=0) { mapOverlays.add(itemizedoverlay); // showing all overlay items itemizedoverlay.populateNow(); // Adjusting the zoom level so that you can see all the markers on map mv.getController().zoomToSpan(Math.abs( minLat - maxLat ), Math.abs( minLong - maxLong )); // Showing the center of the map mc.animateTo(new GeoPoint((maxLat + minLat)/2, (maxLong + minLong)/2 )); } mv.postInvalidate();
更多推荐
mapviewballoon
发布评论