我正在开发一个超级克隆,但是当我在网络上运行该应用程序时,它不允许我在地图上看到位置,并且收到此错误,这有帮助!
在这里您还可以看到应用程序执行时的结果
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:rider_app/AllWidgets/Divider.dart';
import 'package:rider_app/Assistants/assistantsMethods.dart';
class MainScreen extends StatefulWidget
{
static const String idScreen = "mainScreen";
@override
_MainScreenState createState() => _MainScreenState();
}
class _MainScreenState extends State<MainScreen>
{
Completer<GoogleMapController> _controllerGoogleMaps = Completer();
GoogleMapController newGoogleMapController;
GlobalKey<ScaffoldState> scaffoldKey = new GlobalKey<ScaffoldState>();
Position currentPosition;
var geoLocator = Geolocator();
double bottomPaddingOfMap = 0;
void locatePosition() async
{
Position position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
currentPosition = position;
LatLng latLngPosition = LatLng(position.latitude, position.longitude);
CameraPosition cameraPosition = new CameraPosition(target: latLngPosition, zoom: 14);
newGoogleMapController.animateCamera(CameraUpdate.newCameraPosition(cameraPosition));
String address = await AssistantsMethods.searchCoordinateAddress(position);
print("Esta es tú dirección :: " + address);
}
static final CameraPosition _kGooglePlex = CameraPosition(
target: LatLng(37.42796133580664, -122.085749655962),
zoom: 14.4746,
);
@override
Widget build(BuildContext context) {
return Scaffold(
key: scaffoldKey,
appBar: AppBar(
title: Text("Ventana Principal"),
),
drawer: Container(
color: Colors.white,
width: 255.0,
child: Drawer(
child: ListView(
children: [
//Drawer Header
Container(
height: 165.0,
child: DrawerHeader(
decoration: BoxDecoration(color: Colors.white),
child: Row(
children: [
Image.asset("images/user_icon.png", height: 65.0,width: 65.0,),
SizedBox(width: 16.0,),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("Nombre del perfil", style: TextStyle(fontSize: 16.0, fontFamily: "Brand-Bold"),),
SizedBox(height: 6.0,),
Text("Perfil Visitante"),
],
),
],
),
),
),
DividerWidget(),
SizedBox(height: 12.0,),
//Drawer Body Controller
ListTile(
leading: Icon(Icons.history),
title: Text("Historia", style: TextStyle(fontSize: 15.0),),
),
ListTile(
leading: Icon(Icons.person),
title: Text("Perfil de visitante", style: TextStyle(fontSize: 15.0),),
),
ListTile(
leading: Icon(Icons.info),
title: Text("Sobre", style: TextStyle(fontSize: 15.0),),
),
],
),
),
),
body: Stack(
children: [
GoogleMap(
padding: EdgeInsets.only(bottom: bottomPaddingOfMap),
mapType: MapType.normal,
myLocationButtonEnabled: true,
initialCameraPosition: _kGooglePlex,
myLocationEnabled: true,
zoomGesturesEnabled: true,
zoomControlsEnabled: true,
onMapCreated: (GoogleMapController controller)
{
_controllerGoogleMaps.complete(controller);
newGoogleMapController = controller;
setState(() {
bottomPaddingOfMap = 300.0;
});
locatePosition();
},
),
Positioned(
top: 45.0,
left: 22.0,
child: GestureDetector(
onTap: ()
{
scaffoldKey.currentState.openDrawer();
},
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(22.0),
boxShadow: [
BoxShadow(
color: Colors.black,
blurRadius: 6.0,
spreadRadius: 0.5,
offset: Offset(
0.7,
0.7,
),
),
],
),
child: CircleAvatar(
backgroundColor: Colors.white,
child: Icon(Icons.menu, color: Colors.black,),
radius: 20.0,
),
),
),
),
Positioned(
left: 0.0,
right: 0.0,
bottom: 0.0,
child: Container(
height: 300.0,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(topLeft: Radius.circular(18.0), topRight: Radius.circular(18.0)),
boxShadow: [
BoxShadow(
color: Colors.black,
blurRadius: 16.0,
spreadRadius: 0.5,
offset: Offset(0.7, 0.7),
)
],
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 18.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(height: 6.0),
Text("Hola,Buen día..", style: TextStyle(fontSize: 12.0),),
Text("A dondé quisieras ir?", style: TextStyle(fontSize: 20.0, fontFamily: "Brand-Bold"),),
SizedBox(height: 20.0),
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(5.0),
boxShadow: [
BoxShadow(
color: Colors.black54,
blurRadius: 6.0,
spreadRadius: 0.5,
offset: Offset(0.7, 0.7),
)
],
),
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Row(
children: [
Icon(Icons.search, color: Colors.blueAccent,),
SizedBox(width: 10.0,),
Text("Buscar una ubicación de entrega")
],
),
),
),
SizedBox(height: 24.0),
Row(
children: [
Icon(Icons.home,color: Colors.grey,),
SizedBox(width: 12.0,),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Agregar Casa"),
SizedBox(height: 4.0,),
Text("La dirección de su casa", style: TextStyle(color: Colors.grey[500], fontSize: 12.0),),
],
),
],
),
SizedBox(height: 10.0),
DividerWidget(),
SizedBox(height: 16.0),
Row(
children: [
Icon(Icons.work,color: Colors.grey,),
SizedBox(width: 12.0,),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Agregar Trabajo"),
SizedBox(height: 4.0,),
Text("La dirección de su trabajo", style: TextStyle(color: Colors.grey[500], fontSize: 12.0),),
],
),
],
),
],
),
),
),
)
],
),
);
}
}
<!-- end snippet -->
我希望你能帮助给我一个解决方案或给我一条道路,以便我可以继续,因为我不知道该怎么做。
出现此错误是因为您尝试在网络上使用 google_maps_flutter - 该网络仅支持 Android 和 iOS。如果您要在 Flutter 网页版上添加 Google 地图插件,则需要使用 google_maps_flutter_web
我也遇到了同样的问题。我做了以下事情并成功了。
从 Google Cloud Console 启用 JavaScript API 并安装 Google 地图 flutter web。
安装后,请记住在
web/index.html
的flutter project
路径上添加以下代码片段,并在以下代码片段的API key
文本位置输入您自己的"YOUR_API_KEY"
。
<head>
<!-- // Other stuff -->
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY"></script>
</head>
修改
<head>
的 web/index.html
标签以加载 Google Maps JavaScript API,如下所示:
<head>
<!-- // Other stuff -->
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY"></script>
</head>
只需在项目中的 web/index.html 标记之前添加此代码
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY"></script>