Strelok
Strelok

Reputation: 113

Map not rendering in Google Maps App

When i run my google maps activity it starts perfectly, but the map doesn't appear, it just stays as shown in the image below:

The emulator stays like this

Here my code:

MapsActivity.java code:

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }


    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = 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));
        if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            return;
        }
    }
}

activity_maps.xml code:

<fragment 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:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.package.MapsActivity" />

google_maps_api.xml code:

<resources>
    <string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">
        AIzaSyCw_UlNpofyOK_GQZE-ao4OIMaSV1iYuEI
    </string>
</resources>

code in Manifest:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    android:name="android.support.multidex.MultiDexApplication">
    <activity android:name=".MainActivity">
        <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.maps.v2.API_KEY"
        android:value="@string/google_maps_key" />

    <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"></activity>
</application>

Error:

08-31 00:24:37.245 4010-4010/com.myPackage.myPackage E/AndroidRuntime: FATAL EXCEPTION: main Process: com.myPackage.myPackage, PID: 4010 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myPackage.myPackage/com.myPackage.myPackage.MapsActivity}: android.view.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class fragment at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: android.view.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class fragment at android.view.LayoutInflater.inflate(LayoutInflater.java:539) at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at android.view.LayoutInflater.inflate(LayoutInflater.java:374) at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) at android.app.Activity.setContentView(Activity.java:2166) at com.myPackage.myPackage.MapsActivity.onCreate(MapsActivity.java:22) at android.app.Activity.performCreate(Activity.java:6237) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)  at android.app.ActivityThread.-wrap11(ActivityThread.java)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:148)  at android.app.ActivityThread.main(ActivityThread.java:5417)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)  Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class fragment at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) at android.view.LayoutInflater.inflate(LayoutInflater.java:492) at android.view.LayoutInflater.inflate(LayoutInflater.java:423)  at android.view.LayoutInflater.inflate(LayoutInflater.java:374)  at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)  at android.app.Activity.setContentView(Activity.java:2166)  at com.myPackage.myPackage.MapsActivity.onCreate(MapsActivity.java:22)  at android.app.Activity.performCreate(Activity.java:6237)  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)  at android.app.ActivityThread.-wrap11(ActivityThread.java)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:148)  at android.app.ActivityThread.main(ActivityThread.java:5417)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)  Caused by: java.lang.RuntimeException: The API key can only be specified once. It is recommended that you use the meta-data tag with the name: com.google.android.geo.API_KEY in the element of AndroidManifest.xml at maps.y.k.a(Unknown Source) at maps.v.c.a(Unknown Source) at com.google.android.gms.maps.internal.CreatorImpl.b(Unknown Source) at com.google.android.gms.maps.internal.CreatorImpl.newMapFragmentDelegate(Unknown Source) at vl.onTransact(:com.google.android.gms.DynamiteModulesB:62) at android.os.Binder.transact(Binder.java:387) at qle.newMapFragmentDelegate(:com.google.android.gms:179) at com.google.android.gms.maps.internal.CreatorImpl.newMapFragmentDelegate(:com.google.android.gms:101) at qld.onTransact(:com.google.android.gms:62) at android.os.Binder.transact(Binder.java:387) at com.google.android.gms.maps.internal.zzc$zza$zza.zzag(Unknown Source) at com.google.android.gms.maps.SupportMapFragment$zzb.zzbow(Unknown Source) at com.google.android.gms.maps.SupportMapFragment$zzb.zza(Unknown Source) at com.google.android.gms.dynamic.zza.zza(Unknown Source) at com.google.android.gms.dynamic.zza.onInflate(Unknown Source) at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source) at android.support.v4.app.Fragment.onInflate(Fragment.java:1142) at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2287) at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120) at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:356) at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:31) at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:79) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:754) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)  at android.view.LayoutInflater.inflate(LayoutInflater.java:492)  at android.view.LayoutInflater.inflate(LayoutInflater.java:423)  at android.view.LayoutInflater.inflate(LayoutInflater.java:374)  at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)  at android.app.Activity.setContentView(Activity.java:2166)  at com.myPackage.myPackage.MapsActivity.onCreate(MapsActivity.java:22)  at android.app.Activity.performCreate(Activity.java:6237)  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)  at android.app.ActivityThread.-wrap11(ActivityThread.java)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:148)  at android.app.ActivityThread.main(ActivityThread.java:5417)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)  08-31 00:25:52.669 4235-4262/com.myPackage.myPackage E/Surface: getSlotFromBufferLocked: unknown buffer: 0xae3f12a0 08-31 00:26:21.749 4235-4366/com.myPackage.myPackage E/b: Authentication failed. Timeout while trying to contact the server. 08-31 00:27:06.051 4235-4366/com.myPackage.myPackage E/b: Authentication failed. Timeout while trying to contact the server. 08-31 00:27:53.984 4235-4366/com.myPackage.myPackage E/b: Authentication failed. Timeout while trying to contact the server. 08-31 00:28:52.837 4235-4366/com.myPackage.myPackage E/b: Authentication failed. Timeout while trying to contact the server. 08-31 00:30:08.276 4235-4366/com.myPackage.myPackage E/b: Authentication failed. Timeout while trying to contact the server. 08-31 00:31:47.002 4235-4366/com.myPackage.myPackage E/b: Authentication failed. Timeout while trying to contact the server. 08-31 00:34:05.692 4235-4366/com.myPackage.myPackage E/b: Authentication failed. Timeout while trying to contact the server. 08-31 00:37:23.748 4235-4366/com.myPackage.myPackage E/b: Authentication failed. Timeout while trying to contact the server. 08-31 00:42:25.948 4235-4366/com.myPackage.myPackage E/b: Authentication failed. Timeout while trying to contact the server. 08-31 00:50:09.034 4235-4366/com.myPackage.myPackage E/b: Authentication failed. Timeout while trying to contact the server. 08-31 01:02:08.900 4235-4366/com.myPackage.myPackage E/b: Authentication failed. Timeout while trying to contact the server. 08-31 01:21:00.389 4235-4366/com.myPackage.myPackage E/b: Authentication failed. Timeout while trying to contact the server. 08-31 01:50:50.869 4235-4366/com.myPackage.myPackage E/b: Authentication failed. Timeout while trying to contact the server. 08-31 02:20:33.906 3416-3496/com.myPackage.myPackage E/Surface: getSlotFromBufferLocked: unknown buffer: 0xae3f10e0 08-31 02:21:03.773 3416-3673/com.myPackage.myPackage E/b: Authentication failed. Timeout while trying to contact the server.

Upvotes: 0

Views: 419

Answers (2)

Charuka Silva
Charuka Silva

Reputation: 13153

  • First check Google Maps Android API is enabled in google developer console
  • Check the project package name is right in google dev console
  • Then check what type of map you want (debug / release)
  • check the right key is added to your resources if you want release type you need to add it on debug and release file too (adding key only debug file will not work if you want the relase type)
  • Then check the SHA key is from your PC and its the right one (debug key/ release key / or you can add both keys in developer console )

Upvotes: 0

Josh Fischer
Josh Fischer

Reputation: 439

It looks as though you named you meta-data token wrong:

Caused by: java.lang.RuntimeException: The API key can only be specified once.    It is recommended that you use the meta-data tag with the name: com.google.android.geo.API_KEY in the element of AndroidManifest.xml at maps.y.k.a(Unknown Source) at maps.v.c.a(Unknown Source) at

You put:

<meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="@string/google_maps_key" />

Try to change it to:

<meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />

Try this.

Upvotes: 0

Related Questions