Question

I'm building an application in which I have to get the map at zoom level. here is the code:

 public class MapView extends Activity {
    protected void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);
            setContentView(R.layout.map_layout);

            GoogleMap mMap;
            float zoom = mMap.getCameraPosition().zoom;
        }
    }

but it is giving an error "The local variable mMap may not have been initialized" at mMap variable and when I put mMap = null; the application is crashed and said "Unfortunately, the MapView has stopped" How can I resolve this error?

Was it helpful?

Solution

Your GoogleMap object is null. You cannot instantiate a GoogleMap object directly, rather, you must obtain one from the getMap() method on a MapFragment or MapView that you have added to your application, according to the official docs.

See here and here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top