android - How do I make my project compatible with getMapAsync? -


i had working code before updating sdk today(for future reference @ question asked date). .getmap used give warnings deprecated not recognized valid input. assuming has happened because of new release of api 24(android nougat). without further ado here's code:

private boolean initmap() {         if (mmap == null) {             mapfragment mapfrag =                     (mapfragment) getfragmentmanager().findfragmentbyid(r.id.map);             mmap = mapfrag.getmapasync();         }         return (mmap != null);     } 

if me make changes integrate .getmapasync() appreciate it.

thank you!

update: here's new , updated code after looking @ suggestions in answers(this not in oncreate)-

private boolean initmap() {         if (mmap == null) {             mapfragment mapfrag = (mapfragment) getfragmentmanager()                     .findfragmentbyid(r.id.map);             mapfrag.getmapasync(this);         }             return (mmap != null);     }      @override     public void onmapready(googlemap googlemap) {         if (googlemap != null) {             mmap = googlemap;         }     } 

you need call this

    mapfrag = (supportmapfragment) getsupportfragmentmanager()             .findfragmentbyid(r.id.map);     mapfrag.getmapasync(this); 

and make actifity (for instance) implement onmapreadycallback. override call method onmapready(googlemap googlemap)


Comments