如何使用标记在android中显示地图 [英] how to display map in android with marker

查看:28
本文介绍了如何使用标记在android中显示地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发 android 应用程序,我是这方面的新手.所以我想知道如何在地图中显示标记以及如何在特定时间更改他的位置,例如定义线程或背景中的任何内容,这些内容将发送纬度和经度值,并且标记会移动

I am working on android app and I am totally newbe in this. So I want to know how to display marker in map and how to change his position on specific time like defining thread or anything in background which will send the latitude and longitude value and marker was move on that

推荐答案

如果您只显示一个项目,MapView.addView() 和稍后使用 setLayoutParams 更新位置 可以解决问题.

If you're going to show just a single item, MapView.addView() and later updating position with setLayoutParams does the trick.

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

这篇关于如何使用标记在android中显示地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆