android - SupportMapFragment.getmap() returns null -


i'm trying load supportmapfragment dynamically in fragment, here oncreateview() method:

@override     public view oncreateview(layoutinflater inflater, viewgroup container,             bundle savedinstancestate) {             view contentview = inflater.inflate(r.layout.frag_map_layout, null);             shopdtos=shoplistfragment.shopdtos;             fragment =supportmapfragment.newinstance();             fragmenttransaction ft = getfragmentmanager().begintransaction();             ft.replace(r.id.map_content, fragment);             ft.commit();             map = fragment.getmap();             mapmarker = map.addmarker(new markeroptions().position(new latlng(0, 0))                     .icon(bitmapdescriptorfactory                             .fromresource(r.drawable.maps_pin)));         return contentview;     } 

unfortunately, googlemap map null. suggestions on how create mapfragment dynamically?

map takes time load, need run code in handler -->

handler handler = new handler(); handler.postdelayed(new runnable()      @override    public void run() {        googlemap googlemap = supportmapfragment.newinstance(new googlemapoptions().zorderontop(true)).getmap();        fragmenttransaction ft = getfragmentmanager().begintransaction();         ft.replace(r.id.map_content, fragment);         ft.commit();        if(googlemap != null) {           googlemap.addmarker(new markeroptions().position(result)).setvisible(true);            // move camera instantly location zoom of 15.           googlemap.movecamera(cameraupdatefactory.newlatlngzoom(result, 15));            // zoom in, animating camera.           googlemap.animatecamera(cameraupdatefactory.zoomto(14), 2000, null);            googlemap.getuisettings().setzoomcontrolsenabled(false);           googlemap.getuisettings().setcompassenabled(false);           googlemap.getuisettings().setmylocationbuttonenabled(false);            handler.removecallbacksandmessages(null);        }         else {             handler.postdelayed(this, 500);        }  }, 500); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -