Hello I'm trying to add MapView to LinearLayout this is my code:
GoogleMap mMap = mMapView.getMap();
if (mMap != null) {
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(-33.87365, 151.20689), 10);
if (cameraUpdate != null)
mMap.moveCamera(cameraUpdate);
setUpMap(mMap);
}
documantation says; Wait for a GoogleMap
to become available from a MapFragment
or MapView
that you have added to your application. You can verify that the GoogleMap
is available by calling the getMap()
method and checking that the returned object is not null.
But i still get
java.lang.NullPointerException: CameraUpdateFactory is not initialized.
is there any way to check cameraUpdateFactory is ready?
You can force an initialization with the following code
try {
MapsInitializer.initialize(context);
} catch (GooglePlayServicesNotAvailableException impossible) {
/* Impossible */
}
Place this snippet in your onCreate
method to the top and it should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With