【问题标题】:osmdroid shows empty maposmdroid 显示空地图
【发布时间】:2016-03-24 22:16:01
【问题描述】:

我正在编写一个 Android 应用程序并想显示一个 OSM 地图。我试过教程,但地图一直是空的。

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import org.osmdroid.api.IMapController;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;


public class MainActivity extends AppCompatActivity {

    /** Called when the activity is first created. */
    private IMapController mapController;
    private MapView mapView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);
        mapView = (MapView) findViewById(R.id.map);
        mapView.setTileSource(TileSourceFactory.MAPNIK);
        mapView.setMultiTouchControls(true);
        mapController = mapView.getController();
        mapController.setZoom(15);
        GeoPoint poin1 = new GeoPoint(48.8583, 2.2944);
        mapController.setCenter(point1);
    }
}

我使用 osmdroid 4.3。

提前致谢, 普莱博

【问题讨论】:

  • 请发帖activity_main.xml
  • <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <org.osmdroid.views.MapView android:id="@+id/map" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </LinearLayout>
  • 这很奇怪,因为您的代码是正确的。 logcat 有什么错误吗?
  • 另外,你可以试试osmdroid 5.1

标签: android osmdroid


【解决方案1】:

如果您的目标是 API23 并在 23+ 模拟器上运行,那么您必须提示用户授予权限。请参阅 v5.1 或更高版本的示例应用程序。您还需要某种本地存储来存储切片缓存。

【讨论】:

  • 谢谢,现在可以了!奇怪的是我只需要在运行时请求外部存储权限,而不是互联网权限:D
猜你喜欢
  • 1970-01-01
  • 2013-07-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多