Skip to content

Commit 653f898

Browse files
committed
Fixed crash occurring on the map screens when the views were not laid out yet.
1 parent 174bd2e commit 653f898

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

Android/src/org/droidplanner/android/maps/providers/google_map/GoogleMapFragment.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import java.util.Collections;
7373
import java.util.HashSet;
7474
import java.util.List;
75+
import java.util.Locale;
7576
import java.util.Set;
7677
import java.util.concurrent.atomic.AtomicReference;
7778

@@ -658,8 +659,21 @@ public void zoomToFit(List<LatLong> coords) {
658659
getMapAsync(new OnMapReadyCallback() {
659660
@Override
660661
public void onMapReady(GoogleMap googleMap) {
661-
CameraUpdate animation = CameraUpdateFactory.newLatLngBounds(bounds, 100);
662-
googleMap.animateCamera(animation);
662+
final Activity activity = getActivity();
663+
if(activity == null)
664+
return;
665+
666+
final View rootView = ((ViewGroup)activity.findViewById(android.R.id.content)).getChildAt(0);
667+
if(rootView == null)
668+
return;
669+
670+
final int height = rootView.getHeight();
671+
final int width = rootView.getWidth();
672+
Log.d(TAG, String.format(Locale.US, "Screen W %d, H %d", width, height));
673+
if(height > 0 && width > 0) {
674+
CameraUpdate animation = CameraUpdateFactory.newLatLngBounds(bounds, width, height, 100);
675+
googleMap.animateCamera(animation);
676+
}
663677
}
664678
});
665679
}

0 commit comments

Comments
 (0)