Note that there are some explanatory texts on larger screens.

plurals
  1. POmoveCamera with CameraUpdateFactory.newLatLngBounds crashes
    text
    copied!<p>I'm making use of the new <a href="https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/package-summary">Android Google Maps API</a>. </p> <p>I create an activity which includes a MapFragment. In the activity <code>onResume</code> I set the markers into the GoogleMap object and then define a bounding box for the map which includes all of the markers.</p> <p>This is using the following pseudo code:</p> <pre><code>LatLngBounds.Builder builder = new LatLngBounds.Builder(); while(data) { LatLng latlng = getPosition(); builder.include(latlng); } CameraUpdate cameraUpdate = CameraUpdateFactory .newLatLngBounds(builder.build(), 10); map.moveCamera(cameraUpdate); </code></pre> <p>The call to <code>map.moveCamera()</code> causes my application to crash with the following stack:</p> <pre><code>Caused by: java.lang.IllegalStateException: Map size should not be 0. Most likely, layout has not yet at maps.am.r.b(Unknown Source) at maps.y.q.a(Unknown Source) at maps.y.au.a(Unknown Source) at maps.y.ae.moveCamera(Unknown Source) at com.google.android.gms.maps.internal.IGoogleMapDelegate$Stub .onTransact(IGoogleMapDelegate.java:83) at android.os.Binder.transact(Binder.java:310) at com.google.android.gms.maps.internal.IGoogleMapDelegate$a$a .moveCamera(Unknown Source) at com.google.android.gms.maps.GoogleMap.moveCamera(Unknown Source) at ShowMapActivity.drawMapMarkers(ShowMapActivity.java:91) at ShowMapActivity.onResume(ShowMapActivity.java:58) at android.app.Instrumentation .callActivityOnResume(Instrumentation.java:1185) at android.app.Activity.performResume(Activity.java:5182) at android.app.ActivityThread .performResumeActivity(ActivityThread.java:2732) </code></pre> <p>If - instead of the <code>newLatLngBounds()</code> factory method I use <code>newLatLngZoom()</code> method then the same trap does not occur.</p> <p>Is the <code>onResume</code> the best place to draw the markers onto the GoogleMap object or should I be drawing the markers and setting the camera position somewhere else?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload