我想在谷歌地图上做标记后显示 alertDialog 因为我想问用户谷歌地图上的标记是否真实。何时显示删除功能的对话框非常相似。当我试图在谷歌地图上做标记时,我遇到了一些问题,谷歌地图和alerDialog上的标记没有显示。这是我的代码。
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:fyp/model/Location.dart';
import 'package:fyp/model/Task.dart';
import 'package:fyp/service/database.dart';
import 'package:geoflutterfire/geoflutterfire.dart';
import 'package:geolocator/geolocator.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:geocoder/geocoder.dart' as geoCo;
class Geolocation extends StatefulWidget {
final Task task;
const Geolocation({Key key, this.task}) : super(key: key);
@override
_GeolocationState createState() => _GeolocationState(task) ;
}
class _GeolocationState extends State<Geolocation> {
Task task;
_GeolocationState(Task task){
this.task = task;
}
GoogleMapController googleMapController;
Map<MarkerId, Marker> markers = <MarkerId, Marker>{};
Position position;
String addressLocation;
LocationTask loc;
void getMarkers(double lat, double long) {
MarkerId markerId = MarkerId(lat.toString() + long.toString());
Marker _marker = Marker(
draggable: false,
markerId: markerId,
position: LatLng(lat, long),
zIndex: 2,
icon: BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueCyan),
infoWindow: InfoWindow(snippet: addressLocation));
setState(() {
markers[markerId] = _marker;
});
}
getLocation(tapped) async{
final coordinated = new geoCo.Coordinates(tapped.latitude, tapped.longitude);
final FirebaseAuth auth = FirebaseAuth.instance;
final FirebaseUser rd = await auth.currentUser();
final String email = rd.email;
var address = await geoCo.Geocoder.local.findAddressesFromCoordinates(coordinated);
GeoFirePoint firePoint = new GeoFirePoint(tapped.latitude, tapped.longitude);
var firstAddress = address.first;
addressLocation = firstAddress.addressLine;
DateTime _dateTime = DateTime.now();
String id = Firestore.instance
.collection("Location")
.document()
.documentID;
loc = LocationTask(
dateTime: _dateTime,
email: email,
docId: id,
address: addressLocation,
position: firePoint.geoPoint,
noAduan: task.noAduan,
kategori: task.kategori
);
await DatabaseService().addlocation(loc);
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Google Maps"),
backgroundColor: Colors.redAccent,
),
body: Container(
child: GoogleMap(
onTap: (tapped) {
getData(tapped);
},
mapType: MapType.normal,
compassEnabled: true,
myLocationButtonEnabled: true,
onMapCreated: (GoogleMapController controller) {
setState(() {
googleMapController = controller;
});
},
initialCameraPosition: CameraPosition(
target: LatLng(3.12803968168713, 101.5910096431367),
zoom: 15.0),
markers: Set<Marker>.of(markers.values)
),
),
);
}
getData(tapped){
return AlertDialog(
title: Text("Is there true your location"),
content: Text("$addressLocation"),
actions: [
Row(
children: [
FlatButton(
child: Text('Yes'),
onPressed: () {
getLocation(tapped);
},
),
FlatButton(
child: Text('No'),
onPressed: () {
Navigator.pop(context);
},
),
],
)
],
);
}
}
是否因为我多次传递参数“点击”?还是因为我没有使用 showDialog?我曾尝试使用 showDialog 和 alertDialog 但它会显示一些错误。有什么我错过的吗?有人帮我吗?