Reputation: 4124
I keep getting this error:
API key not found. Check that < meta-data android:name=" com.google.android.geo.API_KEY" android:value=" your API key" /> is in the element of AndroidManifest.xml
When my maps activity tries to inflate the activity's fragment.
Has anyone ever experienced this issue?
In my strings file I have:
<string name="google_api_key" translatable="false" templateMergeStrategy="preserve">an api key that i got from google here</string>
I have tried
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_api_key"/>
and typing the key directly into the field:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="an api key that i got from google here"/>
I have also tried:
MapActivity.java
public class MapActivity extends AppCompatActivity {
private static final String MAP_COORDS = "com.mycompany.myapp.map_coordinates";
public static final int MAP_REQUEST_CODE = 453;
private MyObject myObject;
public static Intent newIntent(Context packageContext, MyObject myObject) {
Intent intent = new Intent(packageContext, MapActivity.class);
Bundle bundle = new Bundle();
bundle.putParcelable(MAP_COORDS, myObject);
intent.putExtras(bundle);
return intent;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
}
}
MapActivity.xml
<RelativeLayout
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"
tools:context="com.mycompany.myapp.Views.MasterDetails.MapActivity">
<fragment
android:id="@+id/map"
android:name="com.mycompany.myapp.Views.MasterDetails.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
In my Gradle dependencies
compile 'com.google.android.gms:play-services-maps:7.8.0'
compile 'com.google.android.gms:play-services-location:7.8.0'
AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_api_key"/>
Upvotes: 2
Views: 3274
Reputation: 61
First of all, the API_KEY should be under "application" tag (as follows) and make sure your API_KEY is valid, you should enable "Places API for Android" in the Developer Console, not just "Places API".
<application
android:name=...>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_api_key" />
...
</application>
Also, I can't tell about your MapActivity, but a proper way to start PlacePickerActivity would be something like this:
Kotlin:
val builder = PlacePicker.IntentBuilder()
startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST)
And Java:
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
try {
startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST);
}
catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
}
catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
Hope one of these help, cheers!
Upvotes: 1