Google Maps [API] is grayed out on my mobile device
Hi boy, I really need your help.
I read the instructions for using the Google API at this link: https://developers.google.com/maps/documentation/android/start
I followed all seven steps but was unable to display Google Map in my application.
[I got tired of trying to get the emulator to work, so I decided to generate an APK file and send it to my smartphone] After turning on the app, as soon as I open it, I only see a gray screen and "Google" at the bottom of the screen. that's all, nothing happens.
The app works great when I plug in my device and use debug mode. I tried to install it via adb but it still didn't work.
I have followed many articles over the past three days about this issue, but no matter what I tried it just didn't work.
What am I doing wrong?
Here is my code:
manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="josh.com.googlemapslast" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps" >
<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="AIza**********"/>
</application>
</manifest>
Java main activity:
package josh.com.googlemap2;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
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 MapsActivity extends FragmentActivity implements OnMapReadyCallback {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap map) {
// Add a marker in Sydney, Australia, and move the camera.
LatLng sydney = new LatLng(-34, 151);
map.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
map.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
Main activity:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment" />
Goole_Maps_api.xml
<string name="google_maps_key" translatable="false" templateMergeStrategy="preserve">
AIzaSyAnvkHr4CGYzmROT*******
</string>
</resources>
source to share
Okay, there are two things you should note if you run into a similar situation:
1) There are two google maps api.xml files, one for release and one for debugging. you can find them on the following paths:
\ app \ src \ release \ res \ values
\ app \ src \ debug \ res \ values
Make sure to add your google map key to both files!
2) I didn't find this information in the official source, but you need to generate another SHA1 key for the release file in addition to your regular SHA1 key.
You must have two SHA1 keys, one for the debug version and one for the release version.
Once you have a new key for the release file, add it to your existing Google API Console key on the second line.
source to share