import 'dart:async';
import 'package:google_maps_flutter/google_maps_flutter.dart';
class Locator {
late GoogleMapController mapController;
LatLng specifiedLocation = LatLng(37.7749, -122.4194);
Map<MarkerId, Marker> markers = <MarkerId, Marker>{};
final StreamController<Set<Marker>> _streamController = StreamController<Set<Marker>>();
Stream<Set<Marker>> get markerStream => _streamController.stream;
void _setupMap() {
mapController.animateCamera(
CameraUpdate.newCameraPosition(
CameraPosition(target: specifiedLocation, zoom: 15),
),
);
markerCreate();
_streamController.add(markers.values.toSet());
}
void markerCreate() {
final marker = Marker(
markerId: MarkerId('specifiedLocation'),
position: specifiedLocation,
icon: BitmapDescriptor.defaultMarker,
infoWindow: InfoWindow(title: 'Specified location', snippet: '$specifiedLocation'),
);
markers[MarkerId('specifiedLocation')] = marker;
}
Future<void> onMapCreated(GoogleMapController controller) async {
mapController = controller;
_setupMap();
}
}