i got weird problem googlemap in fragment.
i implemented sort of menu items displayed via viewpager. items can show short googlemap preview. items fragments wich loaded viewpager. show previous , next items viewpager wrapped inside framelayout container (like viewpager previous , next page boundaries).
the problem map not load. last year released version eclipse , there no problem. use different mac , imported project in android studio. things worked. got error in logcat, map shows in other activity mapfragment:
e/dalvikvm﹕ not find class 'android.app.appopsmanager', referenced method com.google.android.gms.common.googleplayservicesutil.zza e/dalvikvm﹕ not find class 'android.app.appopsmanager', referenced method com.google.android.gms.common.hg.a
method 1: mapview in custom fragment (android mapview in fragment) mapview shown can see grid of map. when scroll in viewpager black rectangle appears on place map has been.
<linearlayout android:id="@+id/iteminfo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/itemsubtitle" android:layout_centerhorizontal="true" android:orientation="vertical" > <textview android:id="@+id/itemdistanceinfo" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingbottom="0dp" android:paddingtop="0dp" android:textsize="6pt" android:textcolor="@color/white" android:text="ca. 89 km" android:visibility="gone" /> <relativelayout android:id="@+id/iteminfoprice" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:background="@color/white“ android:layout_margintop="8dp" android:padding="5dp" android:visibility="gone" > <include layout="@layout/price_menu_fragment"/> </relativelayout> <framelayout android:id="@+id/iteminfopicture" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:background="@color/white“ android:layout_margintop="8dp" android:padding="5dp" android:visibility="visible" > <imageview android:id="@+id/itemimage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:src="@drawable/menue_info" android:visibility="invisible" /> <com.google.android.gms.maps.mapview android:id="@+id/mapview" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </framelayout> </linearlayout>
method 2: supportmapfragment in custom fragment here there black view google logo shown in left corner. scrolling in viewpager not show black rectangle in method 1.
<fragment android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.supportmapfragment"/>
i hope can me out.
import com.google.android.gms.maps.supportmapfragment; supportmapfragment mmapfragment = supportmapfragment.newinstance(); fragmentmanager fm = fragment.getchildfragmentmanager(); fm.begintransaction().add(r.id.map, mmapfragment).commit(); mmapfragment.getmapasync(this); @override public void onmapready(googlemap googlemap) { mgooglemap = googlemap; if (activitycompat.checkselfpermission(getcontext(), manifest.permission.access_fine_location) != packagemanager.permission_granted && activitycompat.checkselfpermission(getcontext(), manifest.permission.access_coarse_location) != packagemanager.permission_granted) { // todo: consider calling // activitycompat#requestpermissions // here request missing permissions, , overriding // public void onrequestpermissionsresult(int requestcode, string[] permissions, // int[] grantresults) // handle case user grants permission. see documentation // activitycompat#requestpermissions more details. return; } mgooglemap.setmylocationenabled(true); buildgoogleapiclient(); mgoogleapiclient.connect(); } protected synchronized void buildgoogleapiclient() { mgoogleapiclient = new googleapiclient.builder(getcontext()) .addconnectioncallbacks(this) .addonconnectionfailedlistener(this) .addapi(locationservices.api) .build(); } @override public void onconnected(bundle bundle) { if (activitycompat.checkselfpermission(getcontext(), manifest.permission.access_fine_location) != packagemanager.permission_granted && activitycompat.checkselfpermission(getcontext(), manifest.permission.access_coarse_location) != packagemanager.permission_granted) { // todo: consider calling // activitycompat#requestpermissions // here request missing permissions, , overriding // public void onrequestpermissionsresult(int requestcode, string[] permissions, // int[] grantresults) // handle case user grants permission. see documentation // activitycompat#requestpermissions more details. return; } location mlastlocation = locationservices.fusedlocationapi.getlastlocation( mgoogleapiclient); if (mlastlocation != null) { //place marker @ current position mgooglemap.clear(); //setlocation(mlastlocation.getlatitude(), mlastlocation.getlongitude()); } mlocationrequest = new locationrequest(); mlocationrequest.setinterval(50000); //50 seconds mlocationrequest.setfastestinterval(30000); //30 seconds mlocationrequest.setpriority(locationrequest.priority_balanced_power_accuracy); //mlocationrequest.setsmallestdisplacement(0.1f); //1/10 meter locationservices.fusedlocationapi.requestlocationupdates(mgoogleapiclient, mlocationrequest, this); } @override public void onconnectionsuspended(int i) { toast.maketext(customadapter.getcontext(), "onconnectionsuspended", toast.length_short).show(); } @override public void onconnectionfailed(connectionresult connectionresult) { toast.maketext(customadapter.getcontext(), "onconnectionfailed", toast.length_short).show(); } @override public void onlocationchanged(location location) { sourcelat = location.getlatitude(); sourcelng = location.getlongitude(); getrestaurantdetails(); latlng = new latlng(location.getlatitude(), location.getlongitude()); //latlng = new latlng(lat, lng); //log.wtf("lat lng", lat + " " + lng); mgooglemap.animatecamera(cameraupdatefactory.newlatlngzoom(latlng, 18)); locationservices.fusedlocationapi.removelocationupdates(mgoogleapiclient, this); }
where fragment instance of viewpagerfragment
in xml
<linearlayout android:id="@+id/map" android:layout_width="match_parent" android:layout_height="250dp" />
Comments
Post a Comment