我在Android中使用osmdroid来满足我的地图需求。直到几天前,我能够看到地图,一切都很好,但现在每次我的地图活动启动时,我得到一个空白的地图和以下跟踪:
08-22 07:47:01.113: WARN/org.osmdroid.tileprovider.modules.MapTileDownloader(470): UnknownHostException downloading MapTile: /10/520/387 : java.net.UnknownHostException: Unable to resolve host "tile.openstreetmap.org": No address associated with hostname
08-22 07:47:01.133: WARN/org.osmdroid.tileprovider.modules.MapTileDownloader(470): UnknownHostException downloading MapTile: /10/516/387 : java.net.UnknownHostException: Unable to resolve host "tile.openstreetmap.org": No address associated with hostname
08-22 07:47:01.284: INFO/org.osmdroid.tileprovider.modules.MapTileModuleProviderBase(470): Tile loader can't continue
08-22 07:47:01.284: INFO/org.osmdroid.tileprovider.modules.MapTileModuleProviderBase(470): org.osmdroid.tileprovider.modules.MapTileModuleProviderBase$CantContinueException: java.net.UnknownHostException: Unable to resolve host "tile.openstreetmap.org": No address associated with hostname
08-22 07:47:01.284: INFO/org.osmdroid.tileprovider.modules.MapTileModuleProviderBase(470): at org.osmdroid.tileprovider.modules.MapTileDownloader$TileLoader.loadTile(MapTileDownloader.java:197)
08-22 07:47:01.284: INFO/org.osmdroid.tileprovider.modules.MapTileModuleProviderBase(470): at org.osmdroid.tileprovider.modules.MapTileModuleProviderBase$TileLoader.run(MapTileModuleProviderBase.java:239)
08-22 07:47:01.284: INFO/org.osmdroid.tileprovider.modules.MapTileModuleProviderBase(470): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1081)
08-22 07:47:01.284: INFO/org.osmdroid.tileprovider.modules.MapTileModuleProviderBase(470): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:574)
08-22 07:47:01.284: INFO/org.osmdroid.tileprovider.modules.MapTileModuleProviderBase(470): at java.lang.Thread.run(Thread.java:1020)
08-22 07:47:01.284: INFO/org.osmdroid.tileprovider.modules.MapTileModuleProviderBase(470): Caused by: java.net.UnknownHostException: Unable to resolve host "tile.openstreetmap.org": No address associated with hostname
08-22 07:47:01.284: INFO/org.osmdroid.tileprovider.modules.MapTileModuleProviderBase(470): at java.net.InetAddress.lookupHostByName(InetAddress.java:496)
08-22 07:47:01.284: INFO/org.osmdroid.tileprovider.modules.MapTileModuleProviderBase(470): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:277)
08-22 07:47:01.284: INFO/org.osmdroid.tileprovider.modules.MapTileModuleProviderBase(470): at java.net.InetAddress.getAllByName(InetAddress.java:249)
08-22 07:47:01.284: INFO/org.osmdroid.tileprovider.modules.MapTileModuleProviderBase(470): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:136)
08-22 07:47:01.284: INFO/org.osmdroid.tileprovider.modules.MapTileModuleProviderBase(470): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
08-22 07:47:01.284: INFO/org.osmdroid.tileprovider.modules.MapTileModuleProviderBase(470): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
08-22 07:47:01.284: INFO/org.osmdroid.tileprovider.modules.MapTileModuleProviderBase(470): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
08-22 07:47:01.284: INFO/org.osmdroid.tileprovider.modules.MapTileModuleProviderBase(470): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
08-22 07:47:01.284: INFO/org.osmdroid.tileprovider.modules.MapTileModuleProviderBase(470): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
08-22 07:47:01.284: INFO/org.osmdroid.tileprovider.modules.MapTileModuleProviderBase(470): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
08-22 07:47:01.284: INFO/org.osmdroid.tileprovider.modules.MapTileModuleProviderBase(470): at org.osmdroid.tileprovider.modules.MapTileDownloader$TileLoader.loadTile(MapTileDownloader.java:171)
08-22 07:47:01.284: INFO/org.osmdroid.tileprovider.modules.MapTileModuleProviderBase(470): ... 4 more
这是我的onCreate代码的外观:
super.onCreate(savedInstanceState);
this.me = this;
this.mMapView = new MapView(this, 256);
//this.mMapView = (MapView) findViewById(R.id.map);
this.mMapView.setTileSource(TileSourceFactory.MAPNIK);
this.mMapView.setClickable(true);
this.mMapView.setBuiltInZoomControls(true);
this.mMapView.getController().setZoom(10);
this.mMapView.getController().setCenter(new GeoPoint(39.461078, 2.856445));
//register BrodCastListener! - remember to unregister!
IntentFilter filter = new IntentFilter();
filter.addAction(UpdateRequester.ACTION);
this.registerReceiver(this.mUpdateReciever, filter);
//make map seen
setContentView(this.mMapView);
}
我的清单文件具有以下权限:
<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"
android:required="true"/>
<uses-feature android:name="android.hardware.wifi" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
有人遇到过这个问题吗,或者你们有什么想法解决这个问题吗?
奇怪的是,它之前一直工作得很好,然而现在出了问题。
这个问题出现在模拟器上。
解决方法:
我所需要做的就是进入项目运行配置(右键项目->运行为->运行配置),然后进入Android应用程序,接着进入“目标”选项卡,在下面的“附加模拟器命令行选项”中添加:
-dns-server 8.8.8.8