osmdroid显示一个空网格

7

我想尝试使用osmdroid实现OpenStreetMap集成,但是我遇到了一个问题,我不知道缺少了什么。情况如下:

症状:地图小部件被显示,但只有一个空的网格。

这是在我的Activity类中:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    MapView mapView = new MapView(this, 256);
    mapView.setTileSource(TileSourceFactory.MAPNIK);
    mapView.setClickable(true);
    mapView.setBuiltInZoomControls(true);
    setContentView(mapView);
}

我尝试选择各种TileSources,但似乎没有任何区别。

我的清单还包括这些权限(作为<manifest>的子级,在<uses-sdk>之后):

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

...我的模拟器可以连接到互联网,例如浏览器可以使用。

osmdroid和slf4j在构建路径中。该应用程序编译没有问题,并且不生成任何异常。

可能出了什么问题?

非常感谢!

已解决:这是因为我的模拟器没有外部存储来缓存地图瓦片。


我的清单还包括这些权限(作为[manifest]的子元素,在[uses-sdk]之后)。 - Peter
我正在使用osmdroid 3.0.7。 - Peter
也许你能帮我一下,@Peter... http://stackoverflow.com/questions/25460443/empty-osmdroid-map-where-to-custom-the-new-map - gumuruh
2个回答

0

我对OSMdroid也很新,但是你可以试试这样做?

setContentView(R.layout.offline_map_activity);
mapView = (MapView) findViewById(R.id.openmapview);

您还需要在res/layouts中拥有offline_map_activity.xml文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

    <org.osmdroid.views.MapView
        android:id="@+id/openmapview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
</LinearLayout>

希望这对你有用。至少这对我的代码有效 :)

2
你好!感谢你的回答!然而,全屏空白地图网格已经显示出来了,这证实了我的问题不是布局相关的:setContentView(mapView) 已经正确工作了。昨晚我意识到问题完全不同:我的模拟器没有外部存储... - Peter
啊,我明白了,难怪哈哈。很高兴你找到了问题 :) - lyk
无论如何,@lyk,你能帮我一下吗?http://stackoverflow.com/questions/25460443/empty-osmdroid-map-where-to-custom-the-new-map - gumuruh

-1

我觉得你的设备没有SD卡。你需要更改缓存路径

OpenStreetMapTileProviderConstants.setCachePath(this.getFilesDir().getAbsolutePath()); 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接