android 如何在Osmdroid中添加标记?

11dmarpk  于 2023-05-21  发布在  Android
关注(0)|答案(1)|浏览(131)

我正在使用OpenStreetMap。我可以添加这张Map并得到当前位置。但是,我不能设置一个标记我的位置。我用的是可画文件,但是我看不到这个标记。
这是我的Android源码:

map = (MapView) findViewById(R.id.map);
            map.setTileSource(TileSourceFactory.MAPNIK);
            map.setMultiTouchControls(true);
            IMapController mapController = map.getController();
            mapController.setZoom(16);

            GeoPoint  currentLocation = new GeoPoint(lat,lon);
            mapController.setCenter(currentLocation);

            OverlayItem myLocationOverlayItem = new OverlayItem("Here", "Current Position", currentLocation);
            Drawable marker = ContextCompat.getDrawable(getApplication(), R.drawable.markerosm);
            myLocationOverlayItem.setMarker(marker);

markerosm.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <stroke
        android:width="2dp"
        android:color="#FFFFFFFF" />
    <gradient
        android:endColor="#DDBBBBBB"
        android:startColor="#DD777777"
        android:angle="90" />
    <corners
        android:bottomRightRadius="7dp"
        android:bottomLeftRadius="7dp"
        android:topLeftRadius="7dp"
        android:topRightRadius="7dp" />
</shape>

我不接受错误,但我看不见。如何解决这个问题?

nzkunb0c

nzkunb0c1#

GeoPoint startPoint = new GeoPoint(20.5992, 72.9342);
Marker startMarker = new Marker(mapView);
startMarker.setPosition(startPoint);
startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
mapView.getOverlays().add(startMarker);

相关问题