OSMDroid main.xml地图视图应该如何显示?

时间:2012-05-09 16:54:18

标签: android openstreetmap osmdroid

警告:Noob警告。

我对Android和OSM都很陌生。我想要的只是一张要显示的地图。

Google的MapView可以是main.xml的根目录,OSM的MapView也可以是root用户吗?

这是我当前的main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

<org.osmdroid.views.MapView
    android:id="@+id/map"
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    tilesource="MapquestOSM" />

</LinearLayout>

这是我的活动:

public class AndroidManiTestActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.id.map);
    }
}

我收到以下错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.anny/com.anny.AndroidManiTestActivity}: 

Android.content.res.Resources$NotFoundException: Resource ID #0x7f050000 type #0x12 is not valid

修改: 我正在运行osmdroid 3.0.8和slf4j 1.5.8。

1 个答案:

答案 0 :(得分:2)

你的setContentView(..)需要一个.layout参数而不是.id,所以它是

setContentView(R.layout.main);

之后,您可以使用以下行来引用.map:

findViewById(R.id.map);