Android 地图视图

发布于 2024-10-16 12:44:31 字数 1915 浏览 10 评论 0原文

我正在尝试在 Android 中为 myLocation 添加叠加层。地图显示,但叠加层不显示。我确实使用扩展 ItemizedOverlay 的单独类来显示叠加层。我想知道有没有一种方法可以显示这个单独的点而不创建单独的类?

附件是活动类的源代码。

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);
       }
}

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= new MyLocationOverlay(this, m_vwMap);

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

        mapOverlays.add(m_locationOverlay);
       }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

很酷不放纵 2024-10-23 12:44:31

您需要在 m_vwMap 上调用 invalidate() ,以便它会自行重绘。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文