首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在android中使用标记显示地图

如何在android中使用标记显示地图
EN

Stack Overflow用户
提问于 2011-05-26 22:41:56
回答 1查看 16K关注 0票数 16

我正在开发android应用程序,我在这方面完全是新手。所以我想知道如何在地图上显示标记,以及如何在特定的时间改变标记的位置,比如在后台定义线程或任何东西,它将发送经纬度值并将标记移动到该位置上

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-05-26 23:51:14

如果你打算只显示一个项目,MapView.addView()和稍后用setLayoutParams更新position就能解决这个问题。

private ImageView mCurrentPointer;

@Override
public void onLocationChanged(Location l) {
    int latitude = (int) (l.getLatitude() * 1e6);
    int longitude = (int) (l.getLongitude() * 1e6);
    // Prepare new LayoutParams object that centers on our new latitude/longitude
    MapView.LayoutParams lp = new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT, 
            MapView.LayoutParams.WRAP_CONTENT, new GeoPoint(latitude, longitude),
            MapView.LayoutParams.CENTER);

    if (mCurrentPointer == null) {
        // If "current location" pin is null, we haven't added it
        // to MapView yet. So instantiate it and add it to MapView:
        mCurrentPointer = new ImageView(this); 
        mCurrentPointer.setImageResource(R.drawable.ic_maps_indicator_current_position);
        mMapView.addView(mCurrentPointer, lp);
    } else {
        // If it's already added, just update its location
        mCurrentPointer.setLayoutParams(lp);
    }
}
票数 17
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6140433

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档