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>
Well, I know, this isn't really a solution for the name space problem, maybe this might help.
Since I don't know any XML solution, I did it programmatically:
So the Google Map is initialized default but gets its parameters directly after that from the code.
Obviously this is just a mis-lead Lint check error. You can remove it when, in Eclipse's Problem view, you right-click the line with the error, select the Quick fix option and select e.g. Ignore Check for project.
The error goes away, the project builds and the app runs perfectly well.
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
Second: https://developers.google.com/maps/documentation/android/intro
Select
Project > Properties
, selectJava Build Path
, and navigate toLibraries
. SelectAdd External Jars
, include the following jar files, and click OK:Now my project shows no errors anymore :)
There is another workaround that lets you continue to set everything up in layout files instead of in the Java code. Since the error only seems to happen when the
SupportMapFragment
is a child of aViewGroup
in the layout file, one can extract the<fragment>
element into its own layout file and then just include it in the desired larger layout.For example, given that you are trying to do this:
my_awesome_layout.xml
You could instead break it up like so:
include_map_fragment.xml
my_awesome_layout.xml
I've got exactly the same problem. The provided example
works fine, but if you try to add it into a parent element it refuses to accept the xmlns. If you move the xmlns declaration to the top element it still refuses to accept the map prefix in the fragment:
Now if you extend SupportMapFragment and use a custom view such as this:
...then it doesn't complain and the resultant map is correct. For me that raises further problems however as there are no decent examples of how to do this subclassing, you have to do more than override onCreateView and when I try to do anything to the map subsequently I get the following:
...even if I wait 30 seconds after the map has appeared.(only first loading)
I don't think you can put XML comments inside a tag like you are doing with
<!-- Definition -->
. If you remove that does the problem still occur?