osmdroid MapTileDownloader 现在显示 403 禁止作为 HTTP 响应 [英] osmdroid MapTileDownloader now showing 403 forbidden as HTTP response
问题描述
我已经成功使用 osmdroid-android-4.1.jar 一段时间来在我的应用程序中显示 OSM 地图图块.现在,从昨天开始,我根本没有显示任何图块.当我将手机连接到 PC 时,我在日志中看到 403 禁止响应.我使用 Android Studio 在 Ubuntu 机器上构建了该应用程序.我还没有很好地理解 .aar 文件,难道 4.1jar 现在已经过时并且没有设置正确的用户代理?
I have successfully been using osmdroid-android-4.1.jar for a while to display OSM map tiles in my app. Now, since yesterday, I don't get any tiles at all displayed. When I connect my phone to the PC I see the 403 forbidden response in the log. I built the app on an Ubuntu machine using Android Studio. I haven't got a good understanding of .aar file yet, could it be that the 4.1jar is now outdated and not setting the correct user-agent?
我知道现在不支持 Mapquest,但我使用的是 Mapnik 瓷砖
I know Mapquest isn't supported now but I'm using Mapnik tiles
感谢收到所有信息
更新我刚刚在我的 Windows PC 上尝试了一个旧的基于 Eclipse 的项目.它使用 4.1 jar,我在模拟器中运行它.我看到相同的 403 响应,但没有地图图块.瓦片来源是
Update I've just tried an old Eclipse based project on my Windows PC. That uses 4.1 jar and I ran it in an emulator. I see the same 403 response and no map tiles. The tile source is
mMapView.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
mMapView.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
我知道这个项目曾经有效.缓存图块显示 Ok 但如果我移动地图 - 没有图块.
I know this project used to work. The cache tiles show Ok but if I move the map - no tiles.
整个代码是
public class OsmdroidDemoMap extends Activity {
private MapView mMapView;
private MapController mMapController;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.osm_main);
mMapView = (MapView) findViewById(R.id.mapview);
mMapView.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
mMapView.setBuiltInZoomControls(true);
mMapController = (MapController) mMapView.getController();
mMapController.setZoom(13);
GeoPoint gPt = new GeoPoint(51500000, -150000);
mMapController.setCenter(gPt);
}
}
/* HAVE THIS AS YOUR osm_main.xml
---------------------------------------------------------- XML START
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<org.osmdroid.views.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true" />
</LinearLayout>
---------------------------------------------------------- XML END
Include slf4j-android-1.5.8.jar and osmdroid-android-4.1.jar in the build path
(Google search for where to get them from)
*/
我之前已经发布了此代码作为答案和最小工作 osmdroid 示例的示例 - 现在它不是一个工作示例!
I have posted this code before as an answer and as an example of the smallest working osmdroid sample - well it isn't a working example now!
推荐答案
我们今天遇到了同样的问题.
We had the same issue today.
在 build.gradle 中我们改变了这个:
In build.gradle we changed this:
compile files('libs/osmdroid-android-4.2.jar')
到:
compile 'org.osmdroid:osmdroid-android:5.1@aar'
并添加了这个:
OpenStreetMapTileProviderConstants.setUserAgentValue(BuildConfig.APPLICATION_ID);
在加载地图之前.
您可以在此处阅读有关此问题的更多信息:https://github.com/osmdroid/osmdroid/issues/366.
You can read more about the issue here: https://github.com/osmdroid/osmdroid/issues/366.
希望这对你也有帮助!
这篇关于osmdroid MapTileDownloader 现在显示 403 禁止作为 HTTP 响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!