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

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

问题描述

我的工作在Android上的应用程序,我在这个完全newbe。所以我想知道如何在地图以及如何显示标记改变他的立场的具体时间像定义线程或任何在后台将发送上的纬度和经度值和标记是移动

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

编辑

链接,更多的例子和教程

links for more examples and tutorials

<一个href="http://mobiforge.com/developing/story/using-google-maps-android">http://mobiforge.com/developing/story/using-google-maps-android

<一个href="http://www.vogella.de/articles/AndroidLocationAPI/article.html">http://www.vogella.de/articles/AndroidLocationAPI/article.html

Android的谷歌地图标记

<一个href="http://stackoverflow.com/questions/5963165/show-marker-on-google-map-position-obtained-from-xml">Show标志上的谷歌地图的位置从XML 获得

<一个href="http://stackoverflow.com/questions/2171429/add-marker-on-touched-location-using-google-map-in-android">Add使用谷歌地图的Andr​​oid 标记的触摸位置

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

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