Why is my MapView displaying a blank screen?

Viewed 59

I am creating an app with a MapView that will have markers added to it when the user presses a button. The code for the buttons has not been implemented yet. When the app is run on an emulator the MapView only displays a grey screen with the google logo in the corner. I have had similar problems with apps in the past there the solution was to add a new API Key.

However, I have added a new API Key and enabled it and I am still presented with a blank MapView, I have also made sure that the app is granted access to the location services of the emulator.

Here is the logcat while the app is running:

2021-12-14 12:49:00.442 13690-13734/com.example.myapplication W/e.myapplicatio: Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, linking, allowed)
2021-12-14 12:49:00.442 13690-13734/com.example.myapplication W/e.myapplicatio: Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
2021-12-14 12:49:00.442 13690-13734/com.example.myapplication W/e.myapplicatio: Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, linking, allowed)
2021-12-14 12:49:00.445 13690-13734/com.example.myapplication W/e.myapplicatio: Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
2021-12-14 12:49:00.445 13690-13734/com.example.myapplication W/e.myapplicatio: Accessing hidden method Lsun/misc/Unsafe;->putLong(Ljava/lang/Object;JJ)V (greylist, linking, allowed)
2021-12-14 12:49:00.445 13690-13734/com.example.myapplication W/e.myapplicatio: Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, linking, allowed)
2021-12-14 12:49:00.446 13690-13734/com.example.myapplication W/e.myapplicatio: Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
2021-12-14 12:49:00.446 13690-13734/com.example.myapplication W/e.myapplicatio: Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, linking, allowed)

And Here is the MainActivty Code

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
//import android.support.v4.widget.Toolbar;

import android.os.Bundle;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MainActivity extends AppCompatActivity implements OnMapReadyCallback {
   private MapView mapView;
   private GoogleMap gmap;

   private static final String MAP_VIEW_BUNDLE_KEY = "MapViewBundleKey";

   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);

       Bundle mapViewBundle = null;
       if(savedInstanceState != null){
           mapViewBundle = savedInstanceState.getBundle(MAP_VIEW_BUNDLE_KEY);
       }

       mapView = findViewById(R.id.map_View);
       mapView.onCreate(mapViewBundle);
       mapView.getMapAsync(this);

   }

   @Override
   public void onSaveInstanceState(Bundle outState){
       super.onSaveInstanceState(outState);

       Bundle mapViewBundle = outState.getBundle(MAP_VIEW_BUNDLE_KEY);
       if(mapViewBundle == null){
           mapViewBundle = new Bundle();
           outState.putBundle(MAP_VIEW_BUNDLE_KEY, mapViewBundle);
       }

       mapView.onSaveInstanceState(mapViewBundle);
   }

   @Override
   protected void onResume(){
       super.onResume();
       mapView.onResume();
   }

   @Override
   protected void onStart(){
       super.onStart();
       mapView.onStart();
   }

   @Override
   protected void onStop(){
       super.onStop();
       mapView.onStop();
   }

   @Override
   protected void onPause(){
       super.onPause();
       mapView.onPause();
   }

   @Override
   protected void onDestroy(){
       super.onDestroy();
       mapView.onDestroy();
   }

   @Override
   public void onLowMemory(){
       super.onLowMemory();
       mapView.onLowMemory();
   }

   @Override
   public void onMapReady(GoogleMap googleMap){
     /*  gmap = googleMap;
       gmap.setMinZoomPreference(12);
       LatLng ny = new LatLng(40.7143528, -74.0059731);
       gmap.moveCamera(CameraUpdateFactory.newLatLng(ny));*/

       gmap = googleMap;

       // Add a marker in Sydney and move the camera
       /*LatLng sydney = new LatLng(-34, 151);
       mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
       mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));*/

       //Add a marker in Belfast City Airport
       LatLng bca = new LatLng (54.617611, -5.8718491);
       gmap.addMarker(new MarkerOptions().position(bca).title("Belfast City Airport"));
       gmap.moveCamera(CameraUpdateFactory.newLatLng(bca));
       gmap.moveCamera(CameraUpdateFactory.newLatLngZoom(bca, 12.0f));

   }

}



Does anybody have any suggestions on how to fix this?

0 Answers
Related