Search code examples
androidosmdroid

osmdroid MapTileDownloader now showing 403 forbidden as HTTP response


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?

I know Mapquest isn't supported now but I'm using Mapnik tiles

All information gratefully received

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);

I know this project used to work. The cache tiles show Ok but if I move the map - no tiles.

The entire code is

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)
*/

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!


Solution

  • We had the same issue today.

    In build.gradle we changed this:

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

    to:

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

    And added this:

    OpenStreetMapTileProviderConstants.setUserAgentValue(BuildConfig.APPLICATION_ID);
    

    before loading the map.

    You can read more about the issue here: https://github.com/osmdroid/osmdroid/issues/366.

    Hope this helps you too!