android - Multiple Google Maps Lite in FirebaseRecycler -
i tried make running, thing got grey grid google logo on in left bottom corner in place of fragment. maps intented displayed in cardview loaded firebaserecycleradapter. there no errors thrown , api key correct. when scroll items fast , down several times, maps appear load on each scroll. when left without scrolling, nothing loads.
the card's xml is:
linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:card_view="http://schemas.android.com/apk/res-auto" xmlns:map="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.cardview android:layout_width="fill_parent" android:layout_height="wrap_content" card_view:cardusecompatpadding="true" card_view:cardelevation="1dp" card_view:cardcornerradius="0dp" android:layout_marginleft="-3dp" android:layout_marginright="-3dp" android:id="@+id/cv"> <com.google.android.gms.maps.mapview class="com.google.android.gms.maps.mapfragment" android:id="@+id/maplite" android:layout_width="match_parent" android:layout_height="150dp" map:maptype="normal" map:litemode="true"/> </android.support.v7.widget.cardview> </linearlayout>
the code firebase adapter follows:
adapter = new firebaserecycleradapter<post, postviewholder>(post.class, r.layout.card_view_item, postviewholder.class, ref.child("message").child(currentgroupkey)) { @override protected void populateviewholder(final postviewholder postviewholder, final post post, int position) { super.populateviewholder(postviewholder, post, position); } };
and code postviewholder:
public class postviewholder extends recyclerview.viewholder implements onmapreadycallback { public mapview mapview; public postviewholder(view itemview) { super(itemview); mapview = (mapview) itemview.findviewbyid(r.id.maplite); mapview.oncreate(null); mapview.getmapasync(this); } @override public void onmapready(googlemap googlemap) { cameraupdate updatecamera = cameraupdatefactory.newcameraposition(new cameraposition(new latlng(40.712784, -74.005941), 10, 0f, 0)); googlemap.movecamera(updatecamera); } }
does know may issue?
i've found answer! problem wrong namespace in xml. i've found resolution studying example: https://github.com/saxman/android-map_list. bellow post right version of files showed above in case have similar problem:
card's xml:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:card_view="http://schemas.android.com/apk/res-auto" xmlns:map="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.cardview android:layout_width="fill_parent" android:layout_height="wrap_content" card_view:cardusecompatpadding="true" card_view:cardelevation="1dp" card_view:cardcornerradius="0dp" android:layout_marginleft="-3dp" android:layout_marginright="-3dp" android:id="@+id/cv"> <com.google.android.gms.maps.mapview android:name="com.google.android.gms.maps.mapfragment" android:id="@+id/maplite" android:layout_width="match_parent" android:layout_height="150dp" map:litemode="true"/> </linearlayout> </android.support.v7.widget.cardview>
the code firebase adapter:
adapter = new firebaserecycleradapter<post, postviewholder>(post.class, r.layout.card_view_item, postviewholder.class, ref.child("message").child(currentgroupkey)) { @override public void onbindviewholder(postviewholder viewholder, int position) { super.onbindviewholder(viewholder, position); viewholder.setmaplocation(52.235474, 21.004057); } @override protected void populateviewholder(final postviewholder postviewholder, final post post, int position) { super.populateviewholder(postviewholder, post, position); } };
and postviewholder:
public class postviewholder extends recyclerview.viewholder { public mapview mapview; protected googlemap mgooglemap; protected latlng mmaplocation; public postviewholder(final view itemview) { super(itemview); mapview = (mapview) itemview.findviewbyid(r.id.maplite); mapview.oncreate(null); mapview.getmapasync(new onmapreadycallback() { @override public void onmapready(googlemap googlemap) { mgooglemap = googlemap; mapsinitializer.initialize(itemview.getcontext()); googlemap.getuisettings().setmaptoolbarenabled(true); if (mmaplocation != null) { updatemapcontents(); } } }); } public void setmaplocation(double lat, double lon) { mmaplocation = new latlng(lat, lon); if (mgooglemap != null) { updatemapcontents(); } } protected void updatemapcontents() { mgooglemap.clear(); // update mapview feature data , camera position. mgooglemap.addmarker(new markeroptions().position(mmaplocation)); cameraupdate cameraupdate = cameraupdatefactory.newlatlngzoom(mmaplocation, 10f); mgooglemap.movecamera(cameraupdate); } }
Comments
Post a Comment