osmdroid MapTileDownloader 现在显示 403 forbidden 作为 HTTP 响应
osmdroid MapTileDownloader now showing 403 forbidden as HTTP response
我已经成功地使用 osmdroid-android-4.1.jar 一段时间来在我的应用程序中显示 OSM 地图图块。
现在,从昨天开始,我根本没有显示任何图块。当我将 phone 连接到 PC 时,我在日志中看到 403 forbidden 响应。我使用 Android Studio 在 Ubuntu 机器上构建了该应用程序。我还没有很好地理解 .aar 文件,难道是 4.1jar 现在已经过时并且没有设置正确的用户代理吗?
我知道现在不支持 Mapquest,但我正在使用 Mapnik tiles
所有信息感激不尽
更新
我刚刚在我的 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 示例示例 - 现在它不是一个工作示例!
我们今天遇到了同样的问题。
在 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.
希望这对你也有帮助!
我已经成功地使用 osmdroid-android-4.1.jar 一段时间来在我的应用程序中显示 OSM 地图图块。 现在,从昨天开始,我根本没有显示任何图块。当我将 phone 连接到 PC 时,我在日志中看到 403 forbidden 响应。我使用 Android Studio 在 Ubuntu 机器上构建了该应用程序。我还没有很好地理解 .aar 文件,难道是 4.1jar 现在已经过时并且没有设置正确的用户代理吗?
我知道现在不支持 Mapquest,但我正在使用 Mapnik tiles
所有信息感激不尽
更新 我刚刚在我的 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 示例示例 - 现在它不是一个工作示例!
我们今天遇到了同样的问题。
在 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.
希望这对你也有帮助!