Search code examples
androidgoogle-mapssupportmapfragment

Android: Google maps are not showing up at the screen


I'm working to show a simple map on the screen. The problem I'm getting is the map is not loading. It just shows a blank screen with Google's logo in the corner. Here is the code for Map work.

try {
        // Loading map
        initializeMap();
        marker = new MarkerOptions()
                .position(new LatLng(latitude, longitude))
                .title(title)
                .icon(BitmapDescriptorFactory
                        .fromResource(R.drawable.locate_icon));
        marker.anchor(0.5f, 0.5f);
        googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        googleMap.addMarker(marker);
        moveToCurrentLocation(new LatLng(latitude, longitude));

    } catch (Exception e) {
        e.printStackTrace();
    }

private void moveToCurrentLocation(LatLng currentLocation) {
    googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(currentLocation,
            15));
    // Zoom in, animating the camera.
    googleMap.animateCamera(CameraUpdateFactory.zoomIn());
    // Zoom out to zoom level 10, animating with a duration of 2 seconds.
    googleMap.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null);

}

private void initilizeMap() {
    if (googleMap == null) {
        googleMap = ((SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map)).getMap();

        // check if map is created successfully or not
        if (googleMap == null) {
            Toast.makeText(getApplicationContext(),
                    "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                    .show();
        }
    }
}

Any help in this regard will be highly appreciated.


Solution

  • If you can see the google logo at the bottom left but not able to view the map itself then the problem is clear, you don't have the right Map API Key in your AndroidManifest.

    To solve this, login or create a new Google Developer's Console account and generate a new map key and put it in your AndroidManifest file of your project. Please refer to this link for more information.