java - 带有osmdroid的osm map 中的标记

标签 java android map marker osmdroid

我试图在 OSM 中显示标记,但不能。我可以显示 OSM map 和我手机的位置,但没有别的。

这是我的代码:

public class Carte2Activity extends Activity implements LocationListener {
    MapView mapView;
    MapController myMapController;
    MyLocationOverlay location = null;
    double lat;
    double lng;
    LocationManager lm;
    LocationListener ll;

    ArrayList<OverlayItem> anotherOverlayItemArray;
    String[] sources;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main); 
        mapView = (MapView)findViewById(R.id.openmapview);
        mapView.setBuiltInZoomControls(true);
        mapView.setMultiTouchControls(true);

        lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
        ll = new Myll();
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,1000,0,ll);

        myMapController = mapView.getController();
        myMapController.setZoom(10);
        myMapController.setCenter(new GeoPoint((int)(48.785152*1E6), (int)(2.285156*1E6)));


        location = new MyLocationOverlay(getApplicationContext(), mapView);

       //ajouter la loc
        mapView.getOverlays().add(location);
        //afficher
        location.enableMyLocation();

    }      

    private class Myll implements LocationListener{

    public void onLocationChanged(Location location) {
        // TODO Auto-generated method stub
        lat = location.getLatitude();
        lng = location.getLongitude();
        run();
    }

    public void run() {
        // TODO Auto-generated method stub
        location.runOnFirstFix(new Runnable() { public void run() {
            mapView.getController().animateTo(location.getMyLocation());
            }}); 
    }

    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub      
    }

    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub      
    }

    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub      
    }
}

    public void onLocationChanged(Location location) {
        // TODO Auto-generated method stub      
    }

    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub      
    }

    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub      
    }

    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub

    }
}

安卓 list :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="comparateur.carte"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".Carte2Activity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

我不知道我该怎么做。有人可以帮助我吗?

最佳答案

看看这些代码行:

        OverlayItem myLocationOverlayItem = new OverlayItem("Here", "Current Position", currentLocation);
        Drawable myCurrentLocationMarker = this.getResources().getDrawable(R.drawable.person);
        myLocationOverlayItem.setMarker(myCurrentLocationMarker);

        final ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
        items.add(myLocationOverlayItem);

        currentLocationOverlay = new ItemizedIconOverlay<OverlayItem>(items,
                new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
                    public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
                        return true;
                    }
                    public boolean onItemLongPress(final int index, final OverlayItem item) {
                        return true;
                    }
                }, resourceProxy);
        this.mapView.getOverlays().add(this.currentLocationOverlay);

希望对您有所帮助。

关于java - 带有osmdroid的osm map 中的标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11505727/

相关文章:

java - 具有多个 MP3 的单个媒体播放器

android - 如何在 android 中显示印地语文本?

android - 如何根据从互联网下载的图像调整 TextView 宽度

java - 以 LIFO 顺序将条目存储在 Java 映射中

javascript - 使用 OpenLayers 判断 map 图 block 图像是否已成功加载的方法

java - 使用Java将图像上传到MySql数据库

java:如何将文件转换为utf8

java - Netbeans 错误 : Bundler "WebStart JNLP Bundler" (jnlp) failed to produce a bundle

java - RecyclerView 仅在滚动时加载图像

map - Clojure 基于优先级逻辑从 map 中提取值(value)