android - osmdroid MapTileDownloader 现在显示 403 禁止作为 HTTP 响应

标签 android osmdroid

我已经成功使用 osmdroid-android-4.1.jar 一段时间来在我的应用程序中显示 OSM map 图 block 。 现在,从昨天开始,我根本没有显示任何图 block 。当我将手机连接到 PC 时,我在日志中看到 403 禁止响应。我使用 Android Studio 在 Ubuntu 机器上构建了该应用程序。我还没有很好地理解 .aar 文件,是否 4.1jar 现在已经过时并且没有设置正确的用户代理?

我知道现在不支持 Mapquest,但我正在使用 Mapnik 切片

感谢您收到所有信息

更新 我刚刚在我的 Windows PC 上尝试了一个基于 Eclipse 的旧项目。它使用 4.1 jar,我在模拟器中运行它。我看到相同的 403 响应,但没有 map 图 block 。图 block 来源是

mMapView.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);

我知道这个项目曾经有效。缓存图 block 显示“正常”,但如果我移动 map - 没有图 block 。

整个代码是

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 示例的示例 - 但现在它不是一个工作示例!

最佳答案

我们今天遇到了同样的问题。

在 build.gradle 中我们改变了这一点:

compile files('libs/osmdroid-android-4.2.jar')

至:

compile 'org.osmdroid:osmdroid-android:5.1@aar'

并添加了以下内容:

OpenStreetMapTileProviderConstants.setUserAgentValue(BuildConfig.APPLICATION_ID);

加载 map 之前。

您可以在此处阅读有关该问题的更多信息: https://github.com/osmdroid/osmdroid/issues/366 .

希望这对您也有帮助!

关于android - osmdroid MapTileDownloader 现在显示 403 禁止作为 HTTP 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38921072/

相关文章:

android - 沉浸式全屏不隐藏操作栏和状态栏

java - 闹钟管理器唤醒

android - 通过点击 map 获取坐标(openstreetmaps)

android - 在 OSMDroid 中更改用户代理

android - TravisCI 无法测试构建,因为它使用 Android SDK

android - 将 MediaPlayer 与 setOnPreparedListener 一起使用

android - gridview 在 notifiedDatasetChangedCalled 时自动更改位置?

java - Android - Osmdroid 6.0.2,从 SqlTileWriter 切换到 TileWriter(本地存储)

android - OSMDroid main.xml map View 应该如何显示?

android - 有没有 OSMDROID 的替代品?