soy nuevo en Flutter y ahora estoy aprendiendo a cómo implementar Google Maps en mi aplicación. Para hacerlo estoy siguiendo esta guía oficial: https://codelabs.developers.google.com/codelabs/google-maps-in-flutter/#0
El problema es que cuando inicio la aplicación como podéis ver no aparece el mapa aunque si aparece la firma de Google abajo a la izquierda y los botones de zoom.
Llevo horas con esto y no encuentro el problema, he seguido los pasos de la guía estrictamente. Tengo mi API_KEY creada con las SDK de Google Maps para Android i iOS habilitadas.
Este es mi main.dart:
import 'package:google_maps_flutter/google_maps_flutter.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
GoogleMapController mapController;
final LatLng _center = const LatLng(45.521563, -122.677433);
void _onMapCreated(GoogleMapController controller) {
mapController = controller;
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Maps Sample App'),
backgroundColor: Colors.green[700],
),
body: GoogleMap(
onMapCreated: _onMapCreated,
initialCameraPosition: CameraPosition(
target: _center,
zoom: 11.0,
),
),
),
);
}
}
Estas son las dependencias de Google Maps agregadas a pubspec.yaml :
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.3
google_maps_flutter: ^0.5.11
Mi AndroidManifest.xml :
package="com.example.google_maps_codelab">
<application
android:name="io.flutter.app.FlutterApplication"
android:label="google_maps_codelab"
android:icon="@mipmap/ic_launcher">
<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">
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<meta-data
android:name="flutterEmbedding"
android:value="2" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyC9ocbJyX8D921AwBOwv1dPEeiYv5xxxxx"/>
</application>
</manifest>
Mi AppDelegate.swift :
import Flutter
import GoogleMaps
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GMSServices.provideAPIKey("AIzaSyC9ocbJyX8D921AwBOwv1dPEeiYv5xxxxx")
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
Mi Info.plist :
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>io.flutter.embedded_views_preview</key>
<true/>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>google_maps_codelab</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
</dict>
</plist>
Y finalmente, esto es lo que aparece en la consola cuando inicio la app:
√ Built build\app\outputs\apk\debug\app-debug.apk.
I/Choreographer(24225): Skipped 75 frames! The application may be doing too much work on its main thread.
D/EGL_emulation(24225): eglMakeCurrent: 0xaa288ac0: ver 2 0 (tinfo 0xa7965b90)
D/EGL_emulation(24225): eglMakeCurrent: 0xaa288d60: ver 2 0 (tinfo 0xa7965790)
D/ (24225): HostConnection::get() New Host Connection established 0x93978b80, tid 24239
I/zzbz (24225): Making Creator dynamically
W/zygote (24225): Unsupported class loader
W/zygote (24225): Skipping duplicate class check due to unsupported classloader
I/DynamiteModule(24225): Considering local module com.google.android.gms.maps_dynamite:0 and remote module com.google.android.gms.maps_dynamite:221
I/DynamiteModule(24225): Selected remote version of com.google.android.gms.maps_dynamite, version >= 221
V/DynamiteModule(24225): Dynamite loader version >= 2, using loadModule2NoCrashUtils
D/ (24225): HostConnection::get() New Host Connection established 0xa79269c0, tid 24237
W/zygote (24225): Unsupported class loader
W/zygote (24225): Skipping duplicate class check due to unsupported classloader
I/Google Maps Android API(24225): Google Play services client version: 12451000
I/Google Maps Android API(24225): Google Play services package version: 17785022
I/zygote (24225): Do partial code cache collection, code=29KB, data=26KB
I/zygote (24225): After code cache collection, code=29KB, data=26KB
I/zygote (24225): Increasing code cache capacity to 128KB
I/zygote (24225): Background concurrent copying GC freed 13492(1958KB) AllocSpace objects, 0(0B) LOS objects, 50% free, 1838KB/3MB, paused 2.139ms total 124.002ms
E/GoogleMapController(24225): Cannot enable MyLocation layer as location permissions are not granted
D/ (24225): HostConnection::get() New Host Connection established 0x931f5e80, tid 24291
D/EGL_emulation(24225): eglCreateContext: 0x931f11c0: maj 1 min 0 rcv 1
D/EGL_emulation(24225): eglMakeCurrent: 0xaa288ac0: ver 2 0 (tinfo 0xa7965b90)
D/EGL_emulation(24225): eglMakeCurrent: 0x931f11c0: ver 1 0 (tinfo 0x931fc140)
D/EGL_emulation(24225): eglMakeCurrent: 0xaa288ac0: ver 2 0 (tinfo 0xa7965b90)
D/EGL_emulation(24225): eglMakeCurrent: 0xaa288ac0: ver 2 0 (tinfo 0xa7965b90)
D/EGL_emulation(24225): eglMakeCurrent: 0xaa288ac0: ver 2 0 (tinfo 0xa7965b90)
W/DynamiteModule(24225): Local module descriptor class for com.google.android.gms.googlecertificates not found.
I/DynamiteModule(24225): Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:4
I/DynamiteModule(24225): Selected remote version of com.google.android.gms.googlecertificates, version >= 4
W/zygote (24225): Unsupported class loader
W/zygote (24225): Skipping duplicate class check due to unsupported classloader
I/zygote (24225): Do partial code cache collection, code=51KB, data=55KB
I/zygote (24225): After code cache collection, code=51KB, data=55KB
I/zygote (24225): Increasing code cache capacity to 256KB