【问题标题】:How should OSMDroid main.xml map view look?OSMDroid main.xml 地图视图应该如何显示?
【发布时间】:2012-05-10 02:33:43
【问题描述】:

警告:新手警报。

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

Google的MapView可以做main.xml的根,OSM的MapView也可以做根吗?

这是我当前的 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。

【问题讨论】:

    标签: android openstreetmap osmdroid


    【解决方案1】:

    您的 setContentView(..) 需要采用 .layout 参数而不是 .id,所以它是

    setContentView(R.layout.main);
    

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

    findViewById(R.id.map);
    

    【讨论】:

    • 谢谢!我还修复了我的 libs 文件夹,以便正确引用 jar。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-20
    • 2013-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多