reason

替换google map

import 'dart:async';
import 'dart:math';
import 'package:location/location.dart';
import 'package:flutter/material.dart';
import 'package:Parlando/widgets/my_button.dart';
......@@ -22,10 +25,14 @@ class AddressSelectPageState extends State<AddressSelectPage> {
LatLng _center = const LatLng(45.521563, -122.677433);
late GoogleMapController mapController;
bool isLoading = false;
int _markerIdCounter = 1;
Map<MarkerId, Marker> markers = <MarkerId, Marker>{};
late StreamSubscription _locationSubscription;
@override
void dispose() {
_controller.dispose();
_locationSubscription.cancel();
super.dispose();
}
......@@ -40,7 +47,6 @@ class AddressSelectPageState extends State<AddressSelectPage> {
bool serviceEnabled;
PermissionStatus permissionGranted;
serviceEnabled = await location.serviceEnabled();
if (!serviceEnabled) {
serviceEnabled = await location.requestService();
......@@ -48,7 +54,6 @@ class AddressSelectPageState extends State<AddressSelectPage> {
return;
}
}
permissionGranted = await location.hasPermission();
if (permissionGranted == PermissionStatus.denied) {
permissionGranted = await location.requestPermission();
......@@ -57,9 +62,25 @@ class AddressSelectPageState extends State<AddressSelectPage> {
}
}
_locationSubscription =
location.onLocationChanged.listen((LocationData currentLocation) {
// _center = LatLng(currentLocation.latitude!, currentLocation.longitude!);
setState(() {});
_center = LatLng(currentLocation.latitude!, currentLocation.longitude!);
final String markerIdVal = 'marker_id_$_markerIdCounter';
_markerIdCounter++;
final MarkerId markerId = MarkerId(markerIdVal);
final Marker marker = Marker(
markerId: markerId,
position: LatLng(currentLocation.latitude!, currentLocation.longitude!),
);
LatLng sydney =
LatLng(currentLocation.latitude!, currentLocation.longitude!);
mapController.moveCamera(CameraUpdate.newLatLng(sydney));
setState(() {
markers[markerId] = marker;
});
});
}
......@@ -90,8 +111,9 @@ class AddressSelectPageState extends State<AddressSelectPage> {
onMapCreated: _onMapCreated,
initialCameraPosition: CameraPosition(
target: _center,
zoom: 11.0,
zoom: 16.0,
),
markers: Set<Marker>.of(markers.values),
),
),
Expanded(
......