android - How to use google Map Api2 along-with-other-fragments-in-an-app -
am trying create , app 1 activity multiple fragment. using android.support.v4.* build fragment. each item have created far extending fragment, want use google map api2 in application,
all tutoril found far adding "supportmapfragment" element layout file.
"<fragment class="com.google.android.gms.maps.supportmapfragment" android:layout_width="match_parent" android:layout_height="match_parent"/>"
but cannot use way because nested fragment not supporting, how can use google map api2 fragment in application
use mapview suggested in comments
public class interactivemapswidget extends fragment { private mapview mmapview; private googlemap mmap; public void oncreate(bundle savedinstancestate) { super.onactivitycreated(savedinstancestate); log.i(tag, "on created"); activity activity = getactivity(); if (activity != null) { bundle bundle = getarguments(); ` } } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { log.i(tag, "oncreateview"); new dataworkerasynctask(getactivity()).execute(widgetid); mmapview = (mapview) view.findviewbyid(r.id.map); mmapview.oncreate(savedinstancestate); setupmapifneeded(); return view; } @override public void onresume() { super.onresume(); mmapview.onresume(); setupmapifneeded(); } private void setupmapifneeded() { if (mmap == null) { mmap = ((mapview) view.findviewbyid(r.id.map)).getmap(); if (mmap != null) { setupmap(); } } } private void setupmap() { mmap.addmarker(new markeroptions().position(new latlng(0, 0)).title("marker")); } @override public void onpause() { mmapview.onpause(); super.onpause(); } @override public void ondestroy() { mmapview.ondestroy(); super.ondestroy(); } @override public void onlowmemory() { super.onlowmemory(); mmapview.onlowmemory(); } @override public void onsaveinstancestate(bundle outstate) { super.onsaveinstancestate(outstate); } }
layout
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:map="http://schemas.android.com/apk/res-auto" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <linearlayout android:id="@+id/root_container" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <com.google.android.gms.maps.mapview xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" /> </linearlayout> </linearlayout>
Comments
Post a Comment