【发布时间】:2017-11-23 09:48:24
【问题描述】:
首先,我是 OSMdroid 的新手。 我知道关于这个主题还有其他类似的问题,但没有最近的问题,并且旧问题的答案不适用于我的代码......
我无法使用 OSMDroid 获取当前位置。 我使用了 github 上给出的简单教程和前面问题中给出的建议。 我有最新版本的 OSMDroid,但是当我尝试为当前位置添加标签时,什么也没有出现。
我什至没有收到错误,地图只是显示没有当前位置的标记。帮助!这是我的代码。
任何帮助将不胜感激,因为这很烦人!
Java Class
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Context ctx = getApplicationContext();
//important! set your user agent to prevent getting banned from the osm servers
Configuration.getInstance().load(ctx,
PreferenceManager.getDefaultSharedPreferences(ctx));
setContentView(R.layout.activity_map);
mMapView = (MapView) findViewById(R.id.mapview);
mMapView.setTileSource(TileSourceFactory.MAPNIK);
mMapView.setBuiltInZoomControls(true);
mMapView.setMultiTouchControls(true);
IMapController mapController = mMapView.getController();
mapController.setZoom(9);
GeoPoint startPoint = new GeoPoint(52.1237453, 6.9293683);
mapController.setCenter(startPoint);
this.mLocationOverlay = new MyLocationNewOverlay(new GpsMyLocationProvider(ctx),mMapView);
this.mLocationOverlay.enableMyLocation();
mMapView.getOverlays().add(this.mLocationOverlay);
XML 代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<org.osmdroid.views.MapView
android:id="@+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent"
tilesource="Mapnik" />
</LinearLayout>
【问题讨论】: