2011-02-09 88 views
0

我想在Android中爲myLocation添加覆蓋圖。地圖顯示,但覆蓋圖不顯示。我確實使用擴展了ItemizedOverlay的單獨類來顯示疊加層。我想知道有沒有辦法顯示這個單獨的點,而不創建一個單獨的類?Android MapView

附件是活動類的源代碼。

public class WalkAbout extends MapActivity { 

    //for Hello_mapview 
    List<Overlay> mapOverlays; 
    Drawable drawable; 

    private MapView m_vwMap; 
    private MapController m_mapController; 
    private PathOverlay m_pathOverlay; 
    private MyLocationOverlay m_locationOverlay; 

    private ArrayList<GeoPoint> m_arrPathPoints; 
    private ArrayList<OverlayItem> m_arrPicturePoints; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     initLocationData(); 

     initLayout(); 
    } 
    @Override 
    protected boolean isRouteDisplayed() { 
     return false; 
    } 

    private void initLocationData() { 
     // TODO 
    } 

    private void initLayout() { 
     //instantiate XML File into corresponding view objects. 
     //Then inflate new view from XML resource. 
     setContentView(R.layout.map_layout); 
     MapView m_vwMap = (MapView)findViewById(R.id.mapview); 
     m_vwMap.setBuiltInZoomControls(true); 
     m_vwMap.setSatellite(true); 

     //retrieve list of overlay objects 
     mapOverlays=m_vwMap.getOverlays(); 

     //set market for overlays 
     drawable=this.getResources().getDrawable(R.drawable.item); 
     drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), 
            drawable.getIntrinsicHeight()); 

     //create OverlayItem with my location 
     m_locationOverlay= new MyLocationOverlay(this, m_vwMap); 

     //enable market to set location and direction 
     m_locationOverlay.enableCompass(); 
     m_locationOverlay.enableMyLocation(); 

     mapOverlays.add(m_locationOverlay); 
     } 
} 
+0

我沒有看到你實際使用'Drawable`的地方。你創建了一個覆蓋層,但你實際上並沒有放入任何東西,或者將它的標記設置爲你的drawable。我也不明白你爲什麼不願意創建另一個班級。它看起來像你已經有一個名爲`MyLocationOverlay`。 – 2011-02-09 01:27:28

回答

0

您需要在您的m_vwMap上調用invalidate(),以便重繪自己。