2014-05-24 3 views
4

//// OSMdroidOSMdroid 경계 마커

나는 마커를 추가

, 나는 최대 증가를 매핑 할 필요가 또는 모든 마커를 볼 수 있었다 방식으로 감소 //// 마커를 중심으로

내 코드 :

public class mapcode extends Activity { 
    globalvar appState; 
    int stats=0; 
    private MapView mapView; 
    private IMapController mapController; 
    private SimpleLocationOverlay mMyLocationOverlay; 
    private ScaleBarOverlay mScaleBarOverlay; 
    ItemizedIconOverlay<OverlayItem> currentLocationOverlay; 
    DefaultResourceProxyImpl resourceProxy; 

    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); 
     setContentView(R.layout.map); 

     appState = ((globalvar) getApplicationContext()); 





     mapView = (MapView) this.findViewById(R.id.mapview); 
     mapView.setTileSource(TileSourceFactory.MAPNIK); 
     // mapView.setBuiltInZoomControls(true); //кнопка ZOOM +- 
     mapView.setMultiTouchControls(true); 

     mapController = this.mapView.getController(); 
     mapController.setZoom(2); 

     this.mMyLocationOverlay = new SimpleLocationOverlay(this);       
     this.mapView.getOverlays().add(mMyLocationOverlay); 

     this.mScaleBarOverlay = new ScaleBarOverlay(this);       
     this.mapView.getOverlays().add(mScaleBarOverlay); 
//  this.mapView 

     ///////////////// 
     resourceProxy = new DefaultResourceProxyImpl(getApplicationContext()); 
     GeoPoint currentLocation = new GeoPoint(55.860863,37.115046); 
     GeoPoint currentLocation2 = new GeoPoint(63.557413,-156.102119); 


     OverlayItem myLocationOverlayItem = new OverlayItem("Here", "Current Position", currentLocation); 
     Drawable myCurrentLocationMarker = this.getResources().getDrawable(R.drawable.a); 
     myLocationOverlayItem.setMarker(myCurrentLocationMarker); 
     // myLocationOverlayItem.setMarkerHotspot(HotspotPlace.CENTER); //no working/ 

     final ArrayList<OverlayItem> items = new ArrayList<OverlayItem>(); 
     items.add(myLocationOverlayItem); 



     myLocationOverlayItem = new OverlayItem("Here", "Current Position", currentLocation2); 
     myCurrentLocationMarker = this.getResources().getDrawable(R.drawable.a); 
     myLocationOverlayItem.setMarker(myCurrentLocationMarker); 

    // myLocationOverlayItem.setMarkerHotspot(HotspotPlace.CENTER); // no working 


     items.add(myLocationOverlayItem); 



     currentLocationOverlay = new ItemizedIconOverlay<OverlayItem>(items, 
       new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() { 
        public boolean onItemSingleTapUp(final int index, final OverlayItem item) { 
         return true; 
        } 
        public boolean onItemLongPress(final int index, final OverlayItem item) { 
         return true; 
        } 
       }, resourceProxy); 


     this.mapView.getOverlays().add(this.currentLocationOverlay); 
} 

나는 두 개의 마커를 추가했지만 하나만 볼 수 있습니다 :

http://uploads.ru/LvBlZ.png

와 나는 중심 osmdroid 필요가 즉시 모두 마커

http://uploads.ru/DPLl5.png

+2

당신은'zoomToBoundingBox' 방법을 사용할 수 있습니다,하지만 당신은 필요 왼쪽, 아래쪽 및 오른쪽 좌표를 결정하기 위해 모든 마커를 통과합니다. – saiarcot895

+0

오키, 고마워요! – SKULL

답변

11

난 당신이 뭔가 원한다고 생각했다 :

int minLat = Integer.MAX_VALUE; 
int maxLat = Integer.MIN_VALUE; 
int minLong = Integer.MAX_VALUE; 
int maxLong = Integer.MIN_VALUE; 
ArrayList<OverlayItem> items = new ArrayList<OverlayItem>(); 
for (OverlayItem item : items) { 
    GeoPoint point = item.getPoint(); 
    if (point.getLatitudeE6() < minLat) 
     minLat = point.getLatitudeE6(); 
    if (point.getLatitudeE6() > maxLat) 
     maxLat = point.getLatitudeE6(); 
    if (point.getLongitudeE6() < minLong) 
     minLong = point.getLongitudeE6(); 
    if (point.getLongitudeE6() > maxLong) 
     maxLong = point.getLongitudeE6(); 
} 

BoundingBoxE6 boundingBox = new BoundingBoxE6(maxLat, maxLong, minLat, minLong); 
mMapView.zoomToBoundingBox(boundingBox); 
+0

추가'mapController = mMapView.getController(); mapController.zoomToSpan (boundingBox.getLatitudeSpanE6(), boundingBox.getLongitudeSpanE6()); 'mMapView.zoomToBoundingBox (boundingBox);를 수행 한 후 의 mapController.setCenter (boundingBox.getCenter());가 제대로 작동합니다. – Jei

관련 문제