【问题标题】:How to Add Marker in osmdroid?如何在 osmdroid 中添加标记?
【发布时间】:2019-09-06 10:15:47
【问题描述】:

我正在开发 OpenStreetMap。我可以添加这张地图并获取当前位置。但是,我不能为我的位置设置标记。我使用可绘制文件,但我看不到这个标记。

这是我的 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>

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

【问题讨论】:

标签: android maps openstreetmap osmdroid


【解决方案1】:
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);

【讨论】:

  • 我找到了它并且它正在工作。但是我们不要忘记,我们必须使用 osmbonus 包。
猜你喜欢
  • 2017-04-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-22
  • 1970-01-01
相关资源
最近更新 更多