android - When can you call GoogleMap.moveCamera after onMapReady from OnMapReadyCallback? -


the current android google maps api requires call mapfragment.getmapasync onmapreadycallback before can access googlemap. assumed once had googlemap safe call movecamera() seeing crash reports illegalstateexception said map size can't 0. likely, layout has not yet occured map view.

so tried adding viewtreeobserver.onpredrawlistener, , moving movecamera() call onpredraw method, docs "at point, views in tree have been measured , given frame". still see crash reports same problem. can't find documentation — there's questions movecamera cameraupdatefactory.newlatlngbounds crashes pre-date getmapasync api, they're not help.

i had same issue. google maps library throws exception when app try change camera camera update until map has undergone layout (in order method correctly determine appropriate bounding box , zoom level, map must have size). described here.

it's solution:

@override public void onmapready(googlemap googlemap) {     googlemap.setonmaploadedcallback(this); }  @override public void onmaploaded() {     googlemap.animatecamera(cameraupdatefactory.newlatlngbounds(…)); } 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -