【问题标题】:osmdroid MapTileDownloader now showing 403 forbidden as HTTP responseosmdroid MapTileDownloader 现在将 403 禁止显示为 HTTP 响应
【发布时间】:2016-08-12 15:03:45
【问题描述】:

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

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

感谢所有信息

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

mMapView.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);

我知道这个项目曾经奏效。缓存切片显示正常,但如果我移动地图 - 没有切片。

整个代码是

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

【问题讨论】:

    标签: android osmdroid


    【解决方案1】:

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

    在 build.gradle 我们改变了这个:

    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.

    希望这对你也有帮助!

    【讨论】:

    • 感谢您提供的信息,一旦我使用 aar 文件进行编译,这确实有效。我需要非常熟悉,因为我从 Eclipse/Ant 环境迁移到 Android Studio/Gradle 的时间不长。
    • 使用最新的 osmdroid,您实际上会默认将用户代理设置为应用程序 ID(尽管您仍可能需要手动设置)。
    猜你喜欢
    • 2022-01-06
    • 2012-01-08
    • 2017-12-11
    • 1970-01-01
    • 2020-07-07
    • 2017-12-04
    • 2016-08-17
    • 2021-04-10
    • 1970-01-01
    相关资源
    最近更新 更多