Android 未在设备上显示osmdroid映射
我创建了一个简单的osmdroid,并按照其配置 这是我的舱单:Android 未在设备上显示osmdroid映射,android,osmdroid,Android,Osmdroid,我创建了一个简单的osmdroid,并按照其配置 这是我的舱单: <?xml version="1.0" encoding="utf-8"?> 我的活动: protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Context ctx = getApplicationContext(); //important! set your
<?xml version="1.0" encoding="utf-8"?>
我的活动:
protected 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_main);
osm = (MapView) findViewById(R.id.mapView);
osm.setTileSource(TileSourceFactory.MAPNIK);
osm.setBuiltInZoomControls(true);
osm.setMultiTouchControls(true);
mc = (MapController) osm.getController();
mc.setZoom(12);
GeoPoint center = new GeoPoint(36.680725,48.500430);
mc.animateTo(center);
}
@Override
protected void onResume() {
super.onResume();
//this will refresh the osmdroid configuration on resuming.
//if you make changes to the configuration, use
//SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
//Configuration.getInstance().save(this, prefs);
Configuration.getInstance().load(this, PreferenceManager.getDefaultSharedPreferences(this));
}
但当我运行我的应用程序时,设备上没有显示任何内容!我做了github上提到的所有事情,但我不知道我的问题在哪里?我的项目已安装并运行,但我的设备上没有显示任何内容。我正在使用AVD进行测试。
我读过这篇文章,但它的意思是什么?你的意思是地图视图不显示,还是不显示地图分幅 在使用osmdroid的应用程序中,我在用户接受权限之前初始化MapView时遇到问题,因此我创建了一个作为MainActivity的起始页(基本上用户可以接受权限),并将MapView放在另一个活动的片段中。如果您想看一看,源代码可以在
此外,最新的osmdroid版本在sqlite中而不是在文件系统中存储磁贴,因此您不需要写外部存储。这意味着我的显示器是空白的,只有白色。
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.example.sayres.myosm"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'org.osmdroid:osmdroid-android:5.6.4'
compile 'com.github.MKergall:osmbonuspack:6.3'
}
protected 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_main);
osm = (MapView) findViewById(R.id.mapView);
osm.setTileSource(TileSourceFactory.MAPNIK);
osm.setBuiltInZoomControls(true);
osm.setMultiTouchControls(true);
mc = (MapController) osm.getController();
mc.setZoom(12);
GeoPoint center = new GeoPoint(36.680725,48.500430);
mc.animateTo(center);
}
@Override
protected void onResume() {
super.onResume();
//this will refresh the osmdroid configuration on resuming.
//if you make changes to the configuration, use
//SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
//Configuration.getInstance().save(this, prefs);
Configuration.getInstance().load(this, PreferenceManager.getDefaultSharedPreferences(this));
}