我目前正在开发Android应用程序,我需要导入和使用OpenStreetMap。出于这个原因,我使用osmdroid库6.0.1。不幸的是,当我启动应用程序时,由于java.net.UnknownHostException,因此未加载切片。 这就是我在运行应用程序时在模拟器和智能手机上得到的结果: Emulator - Application Screenshot
以下是我移动地图或放大和缩小时反复出现的例外情况。
W/OsmDroid: UnknownHostException downloading MapTile: /0/0/0 : java.net.UnknownHostException: Unable to resolve host "a.tile.openstreetmap.org": No address associated with hostname
I/OsmDroid: Tile loader can't continue: /0/0/0
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
W/OsmDroid: UnknownHostException downloading MapTile: /0/0/0 : java.net.UnknownHostException: Unable to resolve host "b.tile.openstreetmap.org": No address associated with hostname
I/OsmDroid: Tile loader can't continue: /0/0/0
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
这是 AndroidManifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_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-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MapActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
这是我的 activity_map.xml :
<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/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/></LinearLayout>
这是 MapActivity.java :
import android.content.Context;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import org.osmdroid.api.IMapController;
import org.osmdroid.config.Configuration;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
public class MapActivity extends AppCompatActivity {
MapView map = null;
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Context ctx = getApplicationContext();
Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));
setContentView(R.layout.activity_map);
map = (MapView) findViewById(R.id.map);
map.setTileSource(TileSourceFactory.MAPNIK);
IMapController mapController = map.getController();
GeoPoint startPoint = new GeoPoint(48.8583, 2.2944);
mapController.setCenter(startPoint);
}
}
你有什么线索可能是什么问题吗?
提前谢谢!
修改
代码突然起作用了。我没有改变任何事情。我有一天刚开始申请,所有的瓷砖都装满了。我想问题出在网络上,或者开发人员修复了osmdroid中的错误。