Google maps API Key won't display map

6 hours ago 1
ARTICLE AD BOX

enter image description heretrying to display google maps in my application using the google maps API key but only seeing a blank screen. I'm certain I've done everything correctly, not sure whats missing... any help please? I've attached the 3 main files below: MainActivity.java, activity_main.xml, AndroidManifest.xml

The API key is not restricted, billing is enabled, permissions have been added in the manifest file..

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <androidx.fragment.app.FragmentContainerView android:id="@+id/id_map" android:name="com.google.android.gms.maps.SupportMapFragment" android:layout_width="match_parent" android:layout_height="match_parent" /> </RelativeLayout> <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" > <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <!-- Maps API needs OpenGL ES 2.0. --> <uses-feature android:glEsVersion="0x00020000" android:required="true" /> <uses-permission android:name="com.example.permission.MAPS_RECEIVE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <application android:allowBackup="true" android:dataExtractionRules="@xml/data_extraction_rules" android:fullBackupContent="@xml/backup_rules" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.MyGoogleMap" tools:targetApi="31" > <activity android:name=".MainActivity" android:exported="true" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <meta-data android:name="com.google.android.geo.API_KEY" android:value= "xxxxxx" /> </application> </manifest> package com.example.mygooglemap; import android.os.Bundle; import android.util.Log; import androidx.activity.EdgeToEdge; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.OnMapReadyCallback; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.MarkerOptions; public class MainActivity extends AppCompatActivity implements OnMapReadyCallback{ private GoogleMap gMap; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); EdgeToEdge.enable(this); setContentView(R.layout.activity_main); SupportMapFragment mapFragment; mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.id_map); mapFragment.getMapAsync(this); } @Override public void onMapReady(@NonNull GoogleMap googleMap){ Log.d("MAP_TEST", "onMapReady CALLED"); LatLng city = new LatLng(43.79598400,-1.75343800); googleMap.addMarker(new MarkerOptions().position(city).title("City is Here")); // googleMap.moveCamera(CameraUpdateFactory.newLatLng(bradford)); googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(city.latitude, city.longitude), 12f)); } }
Read Entire Article