开发者

Android MapView

I'm trying to add an overlay for myLocation in Android. The map displays, but the overlay does not. I did get the overlay to appear using a separate class that extends ItemizedOverlay. I'm wondering of there is a way to display this individual point without creating a separate class?

Attached is the source code for the activity class.

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=开发者_JS百科 new MyLocationOverlay(this, m_vwMap);

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

        mapOverlays.add(m_locationOverlay);
       }
}


You need to call invalidate() on your m_vwMap so it will redraw itself.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜