Brendan A
Brendan A

Reputation: 21

Google Maps not displaying for Android using Flutter

I am trying to display google maps widget on my screen. The widget works flawlessly for iOS (See Figure 1), but only displays the google logo and a gray screen (See Figure 2) on the Android device and I'm having trouble identifying the issue.

I am guessing that it's an issue with the API key, however, I'm currently just using a public key that I've created with no restrictions just to try and get something to work. I have configured the android manifest correctly

Figure 1: Working iOS output

Figure 2: Not working Android output

Debug Output:

✓ Built build/app/outputs/apk/debug/app-debug.apk.
D/FlutterActivity(31362): Using the launch theme as normal theme.
D/FlutterActivityAndFragmentDelegate(31362): Setting up FlutterEngine.
D/FlutterActivityAndFragmentDelegate(31362): No preferred FlutterEngine was provided. Creating a new FlutterEngine for this FlutterFragment.
D/FlutterActivityAndFragmentDelegate(31362): Attaching FlutterEngine to the Activity that owns this Fragment.
D/FlutterView(31362): Attaching to a FlutterEngine: io.flutter.embedding.engine.FlutterEngine@f81b727
D/FlutterActivityAndFragmentDelegate(31362): Executing Dart entrypoint: main, and sending initial route: /
D/EGL_emulation(31362): eglMakeCurrent: 0xcfd1a5a0: ver 3 0 (tinfo 0xb8ce7e40)
W/Gralloc4(31362): allocator 3.x is not supported
W/Gralloc3(31362): allocator 3.x is not supported
I/zzbz    (31362): Making Creator dynamically
W/s_app_prototyp(31362): Unsupported class loader
I/DynamiteModule(31362): Considering local module com.google.android.gms.maps_dynamite:0 and remote module com.google.android.gms.maps_dynamite:222
I/DynamiteModule(31362): Selected remote version of com.google.android.gms.maps_dynamite, version >= 222
V/DynamiteModule(31362): Dynamite loader version >= 2, using loadModule2NoCrashUtils
I/Google Maps Android API(31362): Google Play services client version: 12451000
I/Google Maps Android API(31362): Google Play services package version: 200616040
W/s_app_prototyp(31362): Accessing hidden method Lsun/misc/Unsafe;->getInt(Ljava/lang/Object;J)I (greylist, linking, allowed)
W/s_app_prototyp(31362): Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
W/s_app_prototyp(31362): Accessing hidden method Lsun/misc/Unsafe;->putObject(Ljava/lang/Object;JLjava/lang/Object;)V (greylist, linking, allowed)
W/s_app_prototyp(31362): Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, linking, allowed)
W/s_app_prototyp(31362): Accessing hidden method Lsun/misc/Unsafe;->objectFieldOffset(Ljava/lang/reflect/Field;)J (greylist,core-platform-api, linking, allowed)
W/s_app_prototyp(31362): Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
W/s_app_prototyp(31362): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
W/s_app_prototyp(31362): Accessing hidden method Lsun/misc/Unsafe;->putLong(Ljava/lang/Object;JJ)V (greylist, linking, allowed)
W/s_app_prototyp(31362): Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
W/s_app_prototyp(31362): Accessing hidden method Lsun/misc/Unsafe;->allocateInstance(Ljava/lang/Class;)Ljava/lang/Object; (greylist, linking, allowed)
W/s_app_prototyp(31362): Accessing hidden method Llibcore/io/Memory;->peekLong(JZ)J (greylist, reflection, allowed)
W/s_app_prototyp(31362): Accessing hidden method Llibcore/io/Memory;->pokeLong(JJZ)V (greylist, reflection, allowed)
W/s_app_prototyp(31362): Accessing hidden method Llibcore/io/Memory;->pokeInt(JIZ)V (greylist, reflection, allowed)
W/s_app_prototyp(31362): Accessing hidden method Llibcore/io/Memory;->peekInt(JZ)I (greylist, reflection, allowed)
W/s_app_prototyp(31362): Accessing hidden method Llibcore/io/Memory;->pokeByte(JB)V (greylist, reflection, allowed)
W/s_app_prototyp(31362): Accessing hidden method Llibcore/io/Memory;->peekByte(J)B (greylist, reflection, allowed)
W/s_app_prototyp(31362): Accessing hidden method Llibcore/io/Memory;->pokeByteArray(J[BII)V (greylist, reflection, allowed)
W/s_app_prototyp(31362): Accessing hidden method Llibcore/io/Memory;->peekByteArray(J[BII)V (greylist, reflection, allowed)
W/s_app_prototyp(31362): Accessing hidden method Lsun/misc/Unsafe;->arrayBaseOffset(Ljava/lang/Class;)I (greylist,core-platform-api, linking, allowed)
W/s_app_prototyp(31362): Accessing hidden method Lsun/misc/Unsafe;->arrayIndexScale(Ljava/lang/Class;)I (greylist, linking, allowed)
W/s_app_prototyp(31362): Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
W/s_app_prototyp(31362): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, reflection, allowed)
W/s_app_prototyp(31362): Accessing hidden field Ljava/nio/Buffer;->address:J (greylist, reflection, allowed)

Android Manifest:

    package="com.example.ms_app_prototype">
    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->
    <application
        android:name="io.flutter.app.FlutterApplication"
        android:label="ms_app_prototype"
        android:icon="@mipmap/ic_launcher">

        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="inserted correct value"/>

        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

Dart Map Widget:

import 'package:google_maps_flutter/google_maps_flutter.dart';

class Map extends StatelessWidget {
  GoogleMapController mapController;

  final LatLng _center = const LatLng(33.509186, -112.020682);

  void _onMapCreated(GoogleMapController controller) {
    mapController = controller;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: GoogleMap(
        onMapCreated: _onMapCreated,
        initialCameraPosition: CameraPosition(
          target: _center,
          zoom: 15.0,
        ),
      ),
    );
  }
}

Upvotes: 1

Views: 6947

Answers (2)

Brendan A
Brendan A

Reputation: 21

I actually just figured this out on my own, but for anybody with the same or a similar issue what I ended up finding is that the operating system I had downloaded with the emulator did not have the Google API's selected for it. Check out the screen shot below with the SDK that I added highlighted. Hope this helps somebody else!

Android SDK with Google API's under the "Show Package Details" Checked Box

Upvotes: 1

wcyankees424
wcyankees424

Reputation: 2664

I would leave this in a comment but I can't leave comments yet :) You did remember to enable the activate the android maps API?

Upvotes: 1

Related Questions