Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Google Maps fragment in the xml. I get "Unexpected namespace prefix"

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".

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".

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>
like image 728
Alex Avatar asked Feb 22 '13 12:02

Alex


2 Answers

I had this problem as well. I did Project/Clean and the error went away and it works fine now.

like image 172
Kent Avatar answered Sep 23 '22 22:09

Kent


You have to do two things:

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

Add the dependency to Google Play Services into your project

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

Second: https://developers.google.com/maps/documentation/android/intro

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 :)

like image 25
marcel Avatar answered Sep 19 '22 22:09

marcel