android - I have an error on my activity -
hope me solve error.
i have public class open :
@suppresswarnings("deprecation") public class addpostactivity extends appcompatactivity {
in wich have code written, on section of map in activity appears error : "cannot resolve method getmap();"
the code : `
mapfragment fm = (mapfragment)getfragmentmanager() .findfragmentbyid(r.id.maps_fragment); map = fm.getmap(); map.setmaptype(googlemap.map_type_normal); muisettings = map.getuisettings(); muisettings.setcompassenabled(true); muisettings.setmylocationbuttonenabled(false);`
*i have tried replace getmap(); getmapasync(); :`
public class addpostactivity extends fragmentactivity implements onmapreadycallback { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_add_post); mapfragment fm = (mapfragment) getfragmentmanager().findfragmentbyid(r.id.maps_fragment); fm.getmapasync(this); } public void onmapready(googlemap map) { map.setmaptype(googlemap.map_type_normal); muisettings = map.getuisettings(); muisettings.setcompassenabled(true); muisettings.setmylocationbuttonenabled(false); } }
but appears public (of second class) in red line
then how can add code of onmapreadycallback in first public class, not appears duplicate public clas , not give erros ?
xml
<fragment android:id="@+id/maps_fragment" android:name="com.google.android.gms.maps.mapfragment" android:layout_width="match_parent" android:layout_height="match_parent" />
unable find problem could. let try these lines.
if implement onmapreadycallback need override onmapready function.
public class getlocationactivity extends appcompatactivity implements onmapreadycallback { googlemap gmap; @override protected void oncreate(bundle savedinstancestate) { .... ... . gmap = ((mapfragment) getfragmentmanager().findfragmentbyid( r.id.gmap)).getmap(); .. .. } @override public void onmapready(googlemap googlemap) { // logic here } }
edited:
remove these lines code. [ remove second class]
then make first class implement onmapreadycallback.
then copy necessary variables , logic first class itself.
// remove below lines code.
public class addpostactivity extends addpostactivity implements onmapreadycallback { private uisettings muisettings; private googlemap map; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.add_post_activity); mapfragment fm = (mapfragment) getfragmentmanager().findfragmentbyid(r.id.maps_fragment); fm.getmapasync(this); } @override public void onmapready(googlemap googlemap) { map.setmaptype(googlemap.map_type_normal); muisettings = map.getuisettings(); muisettings.setcompassenabled(true); muisettings.setmylocationbuttonenabled(false); } }
instead implement same logic in first class itself. let me know queries
Comments
Post a Comment