xml 中的 Android 谷歌地图片段.我得到“意外的命名空间前缀"; [英] Android Google Maps fragment in the xml. I get "Unexpected namespace prefix"

查看:31
本文介绍了xml 中的 Android 谷歌地图片段.我得到“意外的命名空间前缀";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习 android,并按照有关如何使用 Google Maps API V.2 的说明进行操作,现在我可以使用它了.但是,有关如何配置地图初始状态的说明,请参见 developers.google.com,建议在 xml 文件中定义一个命名空间,在本例中为map".

I'm trying to learn android, and having followed the instructions on how to use the Google Maps API V.2 I now got it working. However, the instructions on how to configure the initial state of the maps, found at developers.google.com, suggests a namespace defined in the xml-file, in this case "map".

下面的 xml 代码给出了错误 "Unexpected namespace prefix "map"".尝试在片段标记内定义 xmlns:map 会产生相同的错误,但使用xmlns".

The xml-code below gives med the error "Unexpected namespace prefix "map"". Trying to define the xmlns:map inside the fragment tag gave the same error but with "xmlns".

我显然在这里缺少一些基本的 xml 知识,有人可以帮助我吗?

I'm obviously missing some fundamental xml-knowledge here, can someone help me out?

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"        
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:map="http://schemas.android.com/apk/res-auto"      <!-- Definition -->
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <fragment 
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment"
        map:cameraBearing="112.5"/>                            <!-- PROBLEM -->

</RelativeLayout>

推荐答案

你必须做两件事:

首先:https://docs.google.com/document/pub?id=19nQzvKP-CVLd7_VrpwnHfl-AE9fjbJySowONZZtNHzw

将对 Google Play 服务的依赖添加到您的项目中

Add the dependency to Google Play Services into your project

Project -> Properties -> Android -> Library, Add -> google-play-services_lib

第二:https://developers.google.com/maps/documentation/android/intro

选择项目>属性,选择Java Build Path,然后导航到Libraries.选择Add External Jars,包含以下jar文件,点击OK:

Select Project > Properties, select Java Build Path, and navigate to Libraries. Select Add External Jars, include the following jar files, and click OK:

<android-sdk-folder>/extras/android/compatibility/v4/android-support-v4.jar

现在我的项目不再显示错误了:)

Now my project shows no errors anymore :)

这篇关于xml 中的 Android 谷歌地图片段.我得到“意外的命名空间前缀";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆