Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio: xmlns:map not working

After doing a lot of research, and not finding anything... quick question, does anybody has an idea why Android Studio is not taking the Map tag? The code below is a fragment of the maps sample in the SDK. Already added google play services lib and support, but nothing.

It's showing the error

Unexpected namespace prefix "map" found for tag fragment.

Thanks a lot in advance!

<fragment
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment"
    map:cameraZoom="10" />
like image 900
davidcv5 Avatar asked Jun 07 '13 19:06

davidcv5


1 Answers

I had the same problem once I've been moving the map fragment into FrameLayout (so I could add a button on top of the map).

I don't know what I've really done as I'm a noob in Android apps and XML, but it looks that I found the solution :-)

I tried to make the trick including the fragment from a separate file (using 'include' directive) and once I put the bare map fragment without any namespace definitions it proposed me 2 options: xmlns:map="http://schemas.android.com/apk/res-auto" xmlns:map="http://schemas.android.com/tools" I realized that maybe the 2nd one will work in the original file (although in original file Android Studio is not proposing it, but only the 1st one instead).

Conclusion: Just change this line: xmlns:map="http://schemas.android.com/apk/res-auto" with this: xmlns:map="http://schemas.android.com/tools"

AS I MENTIONED - I'M A NOOB AND MAYBE MY SOLUTION GOT SOME SIDE EFFECTS SO PLEASE LET ME KNOW IF SO (although everything seemed to be working fine by so far...).

That's my working map layout with a button on the top and no errors:

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
             
    xmlns:map="http://schemas.android.com/tools"
             
  tools:context="com.maverickrider.myapp.inviteActivity.MapsActivity"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/purpura_E51B4A">

<fragment
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.MapFragment"

    map:cameraTargetLat="51.513259"
    map:cameraTargetLng="-0.129147"
    map:cameraTilt="30"
    map:cameraZoom="13"
    />

<Button
    android:id="@+id/startActivityButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal|center_vertical"
    android:onClick="cokolwiek"
    android:text="Baton z dupy"
    android:layout_alignParentBottom="true"
    />

</FrameLayout > 
like image 186
Artur Ex Avatar answered Nov 14 '22 23:11

Artur Ex