使用osmdroid时不会出现地图

时间:2014-02-02 02:14:58

标签: android openstreetmap osmdroid

我正在关注使用osmdroid这个简单的教程: http://www.gleisarbeiter.de/2011/03/17/using-openstreetmaps-with-osmdroid-on-android/

但每当我运行应用程序,使用Genymotion android模拟器或真实设备时,我只看到灰色标题而不是地图,如下所示: enter image description here

我的androidmanifest.xml文件是:

<?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.picofoundry.nationalparksofjapan"
     android:versionCode="1"
     android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="19" />

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />

    <uses-feature android:name="android.hardware.location.network" />
    <uses-feature android:name="android.hardware.location.gps" />
    <uses-feature android:name="android.hardware.wifi" />


    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <!-- Splash screen -->
    <activity
        android:name="com.picofoundry.nationalparksofjapan.SplashScreen"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Black.NoTitleBar" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <!-- Main activity -->
    <activity
        android:name="com.picofoundry.nationalparksofjapan.MainActivity"
        android:launchMode="singleTask"
        android:configChanges="orientation|keyboardHidden"
        android:label="@string/app_name" >
    </activity>
</application>
</manifest>

和MainActivity是:

package com.picofoundry.nationalparksofjapan;

import android.os.Bundle;
import android.app.Activity;

import org.osmdroid.views.MapController;
import org.osmdroid.views.MapView;

public class MainActivity extends Activity {

private MapView myOpenMapView;
private MapController myMapController;

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

    myOpenMapView = new MapView(this, 256);
    myOpenMapView.setClickable(true);
    myOpenMapView.setBuiltInZoomControls(true);
    setContentView(myOpenMapView);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}
}

1 个答案:

答案 0 :(得分:1)

如果您使用默认磁贴提供程序(Mapnik),那么由于请求中的用户代理字段不正确,它们最近停止提供磁贴。 Osmdroid 4.1版解决了这个问题。