Reputation: 193
I am currently trying to embed a Google Map into a custom View.
The only thing that the tutorial shows is how to make a full map xml and not a 'windowed' version.
Can anyone help me?
Upvotes: 2
Views: 2116
Reputation: 31
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
past in your activity xml file and change the id of fragment ex:android:id="@+id/map1"
then
goto your java file and past after setcontent in on create
MapFragment mMapFragment = MapFragment.newInstance();
FragmentTransaction fragmentTransaction =
getFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.map1, mMapFragment);
fragmentTransaction.commit();
mMapFragment.getMapAsync(this);
implements onMapReadyCallBack method and overide in the activity
Note:-this work only if you added Google map in application
Upvotes: -1
Reputation: 795
Try this in your xml:
<!-- Map -->
<FrameLayout
android:id="@+id/map_container"
android:layout_width="match_parent"
android:layout_height="200dp"">
</FrameLayout>
And in your code:
// This method adds map fragment to the container.
private void addMapFragment() {
SupportMapFragment mMapFragment = SupportMapFragment.newInstance();
mMapFragment.getMapAsync(this);
getSupportFragmentManager().beginTransaction()
.replace(R.id.map_container, mMapFragment)
.commit();
}
Also use getChildFragmentManager()
instead of getSupportFragmentManager()
if you are inside a fragment.
Upvotes: 3
Reputation: 2749
Inside your custom view xml
file, try changing the size of the map fragment. In the example below I set height and width to 30dp
.
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="30dp"
android:layout_height="30dp"
android:id="@+id/map"
tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment" />
Upvotes: 2