Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wrap GoogleMap fragment into a LinearLayout?

I tried this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <fragment xmlns:map="http://schemas.android.com/apk/res-auto"

          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:name="com.google.android.gms.maps.SupportMapFragment"
          map:mapType="normal"
       />

</LinearLayout>

But I got 2 errors:

  1. <fragment xmlns:map="http://schemas.android.com/apk/res-auto":

Unexpected namespace prefix "xmlns" found for tag fragment

2.map:mapType="normal":

Unexpected namespace prefix "map" found for tag fragment

What am I doing wrong, and how should it looks like in order to integrate more objects except the Google Map in my app...

thnx !

EDIT !!

I tried this, and it works !

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:map="http://schemas.android.com/apk/res-auto"
              map:mapType="normal"

    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

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

</LinearLayout>

Can't understand why.. also can't understand what map:mapType="normal" and xmlns:map="http://schemas.android.com/apk/res-auto" means... ??

like image 894
Adam Avatar asked Mar 29 '13 15:03

Adam


People also ask

How do you create a LinearLayout?

To create a linear layout in which each child uses the same amount of space on the screen, set the android:layout_height of each view to "0dp" (for a vertical layout) or the android:layout_width of each view to "0dp" (for a horizontal layout). Then set the android:layout_weight of each view to "1" .

Can we use linear layout in RelativeLayout inside?

We can use LinearLayout inside RelativeLayout. We can also use RelativeLayout as a Child of LinearLayout.

What is SupportMapFragment?

public class SupportMapFragment extends Fragment. A Map component in an app. This fragment is the simplest way to place a map in an application. It's a wrapper around a view of a map to automatically handle the necessary life cycle needs.


2 Answers

Have you tried:

<LinearLayout 
    xmlns:map="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

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

</LinearLayout>

From http://developer.android.com/reference/com/google/android/gms/maps/SupportMapFragment.html it looks like the two attributes are not needed.

i also substituted class for android:name.

To use the map attributes you need to add the namespace (i think you can add it to the LinearLayout, more information at https://developers.google.com/maps/documentation/android/map#using_xml_attributes .

If the attributes aren't working i'd probably just set the values programmatically.

like image 190
John Boker Avatar answered Nov 07 '22 08:11

John Boker


For what I know it a known bug that if you wrap your map with a layout, you can't use map prefix properties on it and you have to customize the map in your code.

like image 31
Emil Adz Avatar answered Nov 07 '22 08:11

Emil Adz