I am learning how to show google maps onto my app.Currently, I have done everything including adding meta-data tags and generating the API key but when I run my app it just shows me an empty fragment.No map is downloaded .
public class MapsActivity extends AppCompatActivity implements OnMapReadyCallback {
public static final int PERMISSION_REQUEST_CODE = 9001;
private static final int PLAY_SERVICES_ERROR_CODE = 9002;
public static final String TAG = "MapDebug";
private boolean mLocationPermissionGranted;
private GoogleMap mGoogleMap;
@RequiresApi(api = Build.VERSION_CODES.M)
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
SupportMapFragment supportMapFragment= (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map_fragment);
supportMapFragment.getMapAsync(this);
//isServicesOk();
//initGoogleMap();
// SupportMapFragment supportMapFragment=SupportMapFragment.newInstance();
// supportMapFragment.getMapAsync(this::onMapReady);
}
@Override
public void onMapReady(GoogleMap googleMap) {
Toast.makeText(this, "Showing map", Toast.LENGTH_SHORT).show();
}
Xml Layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map_fragment"/>
</RelativeLayout>