在这个Flutter代码,我试图打开谷歌Map从特定的位置,但踢后"显示在Map上"它去Map部分,只显示黑屏。我得到了经度和纬度从一个API,并试图从模拟器启动谷歌Map。在这里,创建一个虚拟显示的大小:[1080,2148]可能会导致问题(https://github.com/flutter/flutter/issues/2897)。它大于设备屏幕大小:[1080,1977],这可能是主要的问题。有人能帮我吗?(这是一个初级代码)
下面是我的代码:
import 'dart:convert';
import 'package:maps_launcher/maps_launcher.dart';
import 'google_map.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
String? _currentIP ;
String? _isp ;
String? _location;
double _latitude=0.0;
double _longitude=0.0;
class NetworkTest extends StatefulWidget {
const NetworkTest({Key? key}) : super(key: key);
@override
State<NetworkTest> createState() => _NetworkTestState();
}
class _NetworkTestState extends State<NetworkTest> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text(
"Network Info",
style: TextStyle(fontWeight: FontWeight.bold, color: Colors.white),
),
centerTitle: true,
),
body: Center(
child: Column(
children: [
const SizedBox(
height: 20,
),
Text(
'Current IP: $_currentIP',
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
color: Colors.indigo),
),
const SizedBox(
height: 20,
),
Text(
'ISP: $_isp',
style:const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
color: Colors.indigo),
),
const SizedBox(
height: 20,
),
Text(
' Location: $_location',
style:const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
color: Colors.indigo),
),
const SizedBox(
height: 20,
),
ElevatedButton(
onPressed: (){
setState(() {
getRequestTest();
});
},
child: const Text('Show Info'),
),
ElevatedButton(
onPressed: (){
getLateLong(_latitude, _longitude);
Navigator.pushNamed(context, '/google_map');
},
child: const Text('Show In Map'),
),
],
),
),
),
);
}
}
void getRequestTest() async {
Uri url = Uri.http("ifconfig.co","json");
http.Response response = await http.get(url);
Map<String, dynamic> json = jsonDecode(response.body);
_currentIP = json["ip"];
_isp = json["asn_org"];
_location = json["region_name"]+','+json["country"] ;
_longitude = json["longitude"];
_latitude = json["latitude"];
}
和谷歌Map代码:
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
double? _longitude;
double? _latitude;
class googleMap extends StatefulWidget {
@override
_MyMapState createState() => _MyMapState();
}
class _MyMapState extends State<googleMap> {
late GoogleMapController mapController;
final LatLng _center = LatLng(_latitude!, _longitude!);
void _onMapCreated(GoogleMapController controller) {
mapController = controller;
}
@override
Widget build(BuildContext context) {
return GoogleMap(
onMapCreated: _onMapCreated,
initialCameraPosition: CameraPosition(
target: _center,
zoom: 11.0,
),
);
}
}
void getLateLong(double late, double long){
_latitude = late;
_longitude = long;
}
here is full log:
Launching lib\main.dart on sdk gphone x86 in debug mode...
Running Gradle task 'assembleDebug'...
Parameter format not correct -
√ Built build\app\outputs\flutter-apk\app-debug.apk.
Installing build\app\outputs\flutter-apk\app.apk...
Debug service listening on ws://127.0.0.1:5030/cOV3RUVFc24=/ws
Syncing files to device sdk gphone x86...
W/PlatformViewsController(14453): Creating a virtual display of size: [1080, 2148] may result in problems(https://github.com/flutter/flutter/issues/2897).It is larger than the device screen size: [1080, 1977].
D/MapsInitializer(14453): preferredRenderer: null
D/zzca (14453): preferredRenderer: null
I/zzca (14453): Making Creator dynamically
I/DynamiteModule(14453): Considering local module com.google.android.gms.maps_dynamite:0 and remote module com.google.android.gms.maps_dynamite:203115000
I/DynamiteModule(14453): Selected remote version of com.google.android.gms.maps_dynamite, version >= 203115000
V/DynamiteModule(14453): Dynamite loader version >= 2, using loadModule2NoCrashUtils
W/System (14453): ClassLoader referenced unknown path:
W/Gralloc4(14453): allocator 3.x is not supported
I/Google Maps Android API(14453): Google Play services client version: 12451000
I/Google Maps Android API(14453): Google Play services package version: 224814040
I/Google Maps Android API(14453): Google Play services maps renderer version(legacy): 203115000
E/MethodChannel#flutter/platform_views(14453): Failed to handle method call
E/MethodChannel#flutter/platform_views(14453): java.lang.RuntimeException: API key not found. Check that <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
E/MethodChannel#flutter/platform_views(14453): at com.google.maps.api.android.lib6.drd.p.a(:com.google.android.gms.dynamite_mapsdynamite@224814040@22.48.14 (150700-0):6)
E/MethodChannel#flutter/platform_views(14453): at com.google.maps.api.android.lib6.auth.f.i(:com.google.android.gms.dynamite_mapsdynamite@224814040@22.48.14 (150700-0):1)
E/MethodChannel#flutter/platform_views(14453): at com.google.maps.api.android.lib6.impl.l.a(:com.google.android.gms.dynamite_mapsdynamite@224814040@22.48.14 (150700-0):24)
E/MethodChannel#flutter/platform_views(14453): at com.google.android.gms.maps.internal.CreatorImpl.b(:com.google.android.gms.dynamite_mapsdynamite@224814040@22.48.14 (150700-0):7)
E/MethodChannel#flutter/platform_views(14453): at com.google.android.gms.maps.internal.CreatorImpl.logInitialization(:com.google.android.gms.dynamite_mapsdynamite@224814040@22.48.14 (150700-0):3)
E/MethodChannel#flutter/platform_views(14453): at com.google.android.gms.maps.internal.g.ba(:com.google.android.gms.dynamite_mapsdynamite@224814040@22.48.14 (150700-0):5)
E/MethodChannel#flutter/platform_views(14453): at fa.onTransact(:com.google.android.gms.dynamite_mapsdynamite@224814040@22.48.14 (150700-0):4)
E/MethodChannel#flutter/platform_views(14453): at android.os.Binder.transact(Binder.java:1043)
E/MethodChannel#flutter/platform_views(14453): at com.google.android.gms.internal.maps.zza.zzc(com.google.android.gms:play-services-maps@@18.0.0:2)
E/MethodChannel#flutter/platform_views(14453): at com.google.android.gms.maps.internal.zze.zzl(com.google.android.gms:play-services-maps@@18.0.0:4)
E/MethodChannel#flutter/platform_views(14453): at com.google.android.gms.maps.MapsInitializer.initialize(com.google.android.gms:play-services-maps@@18.0.0:12)
E/MethodChannel#flutter/platform_views(14453): at com.google.android.gms.maps.MapsInitializer.initialize(com.google.android.gms:play-services-maps@@18.0.0:1)
E/MethodChannel#flutter/platform_views(14453): at com.google.android.gms.maps.zzah.zzb(com.google.android.gms:play-services-maps@@18.0.0:2)
E/MethodChannel#flutter/platform_views(14453): at com.google.android.gms.maps.zzah.createDelegate(com.google.android.gms:play-services-maps@@18.0.0:1)
E/MethodChannel#flutter/platform_views(14453): at com.google.android.gms.dynamic.DeferredLifecycleHelper.zaf(com.google.android.gms:play-services-base@@18.0.1:6)
E/MethodChannel#flutter/platform_views(14453): at com.google.android.gms.dynamic.DeferredLifecycleHelper.onCreate(com.google.android.gms:play-services-base@@18.0.1:1)
E/MethodChannel#flutter/platform_views(14453): at com.google.android.gms.maps.MapView.onCreate(com.google.android.gms:play-services-maps@@18.0.0:4)
E/MethodChannel#flutter/platform_views(14453): at io.flutter.plugins.googlemaps.GoogleMapController.onCreate(GoogleMapController.java:623)
E/MethodChannel#flutter/platform_views(14453): at androidx.lifecycle.FullLifecycleObserverAdapter.onStateChanged(FullLifecycleObserverAdapter.java:36)
E/MethodChannel#flutter/platform_views(14453): at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:361)
E/MethodChannel#flutter/platform_views(14453): at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:188)
E/MethodChannel#flutter/platform_views(14453): at io.flutter.plugins.googlemaps.GoogleMapController.init(GoogleMapController.java:121)
E/MethodChannel#flutter/platform_views(14453): at io.flutter.plugins.googlemaps.GoogleMapBuilder.build(GoogleMapBuilder.java:38)
E/MethodChannel#flutter/platform_views(14453): at io.flutter.plugins.googlemaps.GoogleMapFactory.create(GoogleMapFactory.java:53)
E/MethodChannel#flutter/platform_views(14453): at io.flutter.plugin.platform.SingleViewPresentation.onCreate(SingleViewPresentation.java:186)
E/MethodChannel#flutter/platform_views(14453): at android.app.Dialog.dispatchOnCreate(Dialog.java:419)
E/MethodChannel#flutter/platform_views(14453): at android.app.Dialog.show(Dialog.java:313)
E/MethodChannel#flutter/platform_views(14453): at android.app.Presentation.show(Presentation.java:257)
E/MethodChannel#flutter/platform_views(14453): at io.flutter.plugin.platform.VirtualDisplayController.<init>(VirtualDisplayController.java:95)
E/MethodChannel#flutter/platform_views(14453): at io.flutter.plugin.platform.VirtualDisplayController.create(VirtualDisplayController.java:48)
E/MethodChannel#flutter/platform_views(14453): at io.flutter.plugin.platform.PlatformViewsController$1.createVirtualDisplayForPlatformView(PlatformViewsController.java:212)
E/MethodChannel#flutter/platform_views(14453): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:107)
E/MethodChannel#flutter/platform_views(14453): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:59)
E/MethodChannel#flutter/platform_views(14453): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/MethodChannel#flutter/platform_views(14453): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:296)
E/MethodChannel#flutter/platform_views(14453): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:320)
E/MethodChannel#flutter/platform_views(14453): at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12)
E/MethodChannel#flutter/platform_views(14453): at android.os.Handler.handleCallback(Handler.java:938)
E/MethodChannel#flutter/platform_views(14453): at android.os.Handler.dispatchMessage(Handler.java:99)
E/MethodChannel#flutter/platform_views(14453): at android.os.Looper.loop(Looper.java:223)
E/MethodChannel#flutter/platform_views(14453): at android.app.ActivityThread.main(ActivityThread.java:7656)
E/MethodChannel#flutter/platform_views(14453): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#flutter/platform_views(14453): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/MethodChannel#flutter/platform_views(14453): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/flutter (14453): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(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 <application> element of AndroidManifest.xml, null, java.lang.RuntimeException: API key not found. Check that <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
E/flutter (14453): at com.google.maps.api.android.lib6.drd.p.a(:com.google.android.gms.dynamite_mapsdynamite@224814040@22.48.14 (150700-0):6)
E/flutter (14453): at com.google.maps.api.android.lib6.auth.f.i(:com.google.android.gms.dynamite_mapsdynamite@224814040@22.48.14 (150700-0):1)
E/flutter (14453): at com.google.maps.api.android.lib6.impl.l.a(:com.google.android.gms.dynamite_mapsdynamite@224814040@22.48.14 (150700-0):24)
E/flutter (14453): at com.google.android.gms.maps.internal.CreatorImpl.b(:com.google.android.gms.dynamite_mapsdynamite@224814040@22.48.14 (150700-0):7)
E/flutter (14453): at com.google.android.gms.maps.internal.CreatorImpl.logInitialization(:com.google.android.gms.dynamite_mapsdynamite@224814040@22.48.14 (150700-0):3)
E/flutter (14453): at com.google.android.gms.maps.internal.g.ba(:com.google.android.gms.dynamite_mapsdynamite@224814040@22.48.14 (150700-0):5)
E/flutter (14453): at fa.onTransact(:com.google.android.gms.dynamite_mapsdynamite@224814040@22.48.14 (150700-0):4)
E/flutter (14453): at android.os.Binder.transact(Binder.java:1043)
E/flutter (14453): at com.google.android.gms.internal.maps.zza.zzc(com.google.android.gms:play-services-maps@@18.0.0:2)
E/flutter (14453): at com.google.android.gms.maps.internal.zze.zzl(com.google.android.gms:play-services-maps@@18.0.0:4)
E/flutter (14453): at com.google.android.gms.maps.MapsInitializer.initialize(com.google.android.gms:play-services-maps@@18.0.0:12)
E/flutter (14453): at com.google.android.gms.maps.MapsInitializer.initialize(com.google.android.gms:play-services-maps@@18.0.0:1)
E/flutter (14453): at com.google.android.gms.maps.zzah.zzb(com.google.android.gms:play-services-maps@@18.0.0:2)
E/flutter (14453): at com.google.android.gms.maps.zzah.createDelegate(com.google.android.gms:play-services-maps@@18.0.0:1)
E/flutter (14453): at com.google.android.gms.dynamic.DeferredLifecycleHelper.zaf(com.google.android.gms:play-services-base@@18.0.1:6)
E/flutter (14453): at com.google.android.gms.dynamic.DeferredLifecycleHelper.onCreate(com.google.android.gms:play-services-base@@18.0.1:1)
E/flutter (14453): at com.google.android.gms.maps.MapView.onCreate(com.google.android.gms:play-services-maps@@18.0.0:4)
E/flutter (14453): at io.flutter.plugins.googlemaps.GoogleMapController.onCreate(GoogleMapController.java:623)
E/flutter (14453): at androidx.lifecycle.FullLifecycleObserverAdapter.onStateChanged(FullLifecycleObserverAdapter.java:36)
E/flutter (14453): at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:361)
E/flutter (14453): at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:188)
E/flutter (14453): at io.flutter.plugins.googlemaps.GoogleMapController.init(GoogleMapController.java:121)
E/flutter (14453): at io.flutter.plugins.googlemaps.GoogleMapBuilder.build(GoogleMapBuilder.java:38)
E/flutter (14453): at io.flutter.plugins.googlemaps.GoogleMapFactory.create(GoogleMapFactory.java:53)
E/flutter (14453): at io.flutter.plugin.platform.SingleViewPresentation.onCreate(SingleViewPresentation.java:186)
E/flutter (14453): at android.app.Dialog.dispatchOnCreate(Dialog.java:419)
E/flutter (14453): at android.app.Dialog.show(Dialog.java:313)
E/flutter (14453): at android.app.Presentation.show(Presentation.java:257)
E/flutter (14453): at io.flutter.plugin.platform.VirtualDisplayController.<init>(VirtualDisplayController.java:95)
E/flutter (14453): at io.flutter.plugin.platform.VirtualDisplayController.create(VirtualDisplayController.java:48)
E/flutter (14453): at io.flutter.plugin.platform.PlatformViewsController$1.createVirtualDisplayForPlatformView(PlatformViewsController.java:212)
E/flutter (14453): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:107)
E/flutter (14453): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:59)
E/flutter (14453): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/flutter (14453): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:296)
E/flutter (14453): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:320)
E/flutter (14453): at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12)
E/flutter (14453): at android.os.Handler.handleCallback(Handler.java:938)
E/flutter (14453): at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter (14453): at android.os.Looper.loop(Looper.java:223)
E/flutter (14453): at android.app.ActivityThread.main(ActivityThread.java:7656)
E/flutter (14453): at java.lang.reflect.Method.invoke(Native Method)
E/flutter (14453): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/flutter (14453): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/flutter (14453): )
E/flutter (14453): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
E/flutter (14453): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:177:18)
E/flutter (14453): <asynchronous suspension>
E/flutter (14453): #2 TextureAndroidViewController._sendCreateMessage (package:flutter/src/services/platform_views.dart:1061:18)
E/flutter (14453): <asynchronous suspension>
E/flutter (14453): #3 AndroidViewController.create (package:flutter/src/services/platform_views.dart:771:5)
E/flutter (14453): <asynchronous suspension>
E/flutter (14453): #4 RenderAndroidView._sizePlatformView (package:flutter/src/rendering/platform_view.dart:191:7)
E/flutter (14453): <asynchronous suspension>
E/flutter (14453):
I/bb (14453): Successfully registered with Phenotype.
1条答案
按热度按时间oxosxuxt1#
我会说你没有为GoogleMap提供API密钥。日志显示:
第一个月