update
This commit is contained in:
@@ -110,11 +110,6 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
||||
|
||||
late GoogleMapController googleMapController;
|
||||
|
||||
static CameraPosition initialCameraPosition = const CameraPosition(
|
||||
target: LatLng(7.8939100, -72.5078200),
|
||||
zoom: 14.4746,
|
||||
);
|
||||
|
||||
Set<Marker> markers = {};
|
||||
|
||||
Future<Position> _determinePosition() async {
|
||||
@@ -180,12 +175,22 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<DocumentSnapshot<Map<String, dynamic>>>>
|
||||
getUsersWithActiveStatus() async {
|
||||
var querySnapshot = await FirebaseFirestore.instance
|
||||
.collection('users')
|
||||
.where('estado', isEqualTo: 'activo')
|
||||
.get();
|
||||
Future<List<DocumentSnapshot<Map<String, dynamic>>>> getUsersWithActiveStatus(
|
||||
String _serviceType) async {
|
||||
var querySnapshot;
|
||||
|
||||
if (_serviceType != "Servicio") {
|
||||
querySnapshot = await FirebaseFirestore.instance
|
||||
.collection('users')
|
||||
.where('estado', isEqualTo: 'activo')
|
||||
.where('profesion', isEqualTo: _serviceType)
|
||||
.get();
|
||||
} else {
|
||||
querySnapshot = await FirebaseFirestore.instance
|
||||
.collection('users')
|
||||
.where('estado', isEqualTo: 'activo')
|
||||
.get();
|
||||
}
|
||||
|
||||
return querySnapshot.docs;
|
||||
}
|
||||
@@ -199,6 +204,43 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
||||
|
||||
String _ciudad = '...';
|
||||
|
||||
void _setInitialCameraPosition(String coordsOfCity) {
|
||||
List<String> coords = coordsOfCity.split(',');
|
||||
double lat = double.parse(coords[0]);
|
||||
double lng = double.parse(coords[1]);
|
||||
|
||||
googleMapController.moveCamera(
|
||||
CameraUpdate.newLatLngZoom(
|
||||
LatLng(lat, lng),
|
||||
14.4746,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void updateMarkersForServiceType(String serviceType) {
|
||||
getUsersWithActiveStatus(serviceType).then((value) {
|
||||
markers.clear();
|
||||
for (var doc in value) {
|
||||
final element = doc.data()!;
|
||||
|
||||
if (element['latitude'] != null && element['longitude'] != null) {
|
||||
markers.add(
|
||||
Marker(
|
||||
icon: _markerIcon!,
|
||||
markerId: MarkerId(doc.id),
|
||||
position: LatLng(
|
||||
element['latitude'],
|
||||
element['longitude'],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}).catchError((e) {
|
||||
print('Error al actualizar los marcadores: $e');
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -229,21 +271,8 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
||||
.then((String s) {
|
||||
setState(() {
|
||||
_coordsOfCity = s;
|
||||
_setInitialCameraPosition(_coordsOfCity);
|
||||
});
|
||||
|
||||
if (_coordsOfCity != '0.0,0.0') {
|
||||
List<String> coords = _coordsOfCity.split(',');
|
||||
double lat = double.parse(coords[0]);
|
||||
double lng = double.parse(coords[1]);
|
||||
|
||||
// Asegúrate de que googleMapController esté disponible y no sea nulo
|
||||
googleMapController.moveCamera(
|
||||
CameraUpdate.newLatLngZoom(
|
||||
LatLng(lat, lng),
|
||||
14.4746, // Puedes ajustar el nivel de zoom según tus necesidades
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -263,27 +292,25 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
||||
_markerIcon = icon;
|
||||
});
|
||||
});
|
||||
try {
|
||||
getUsersWithActiveStatus().then((value) {
|
||||
for (var doc in value) {
|
||||
final element = doc.data()!;
|
||||
|
||||
if (element['latitude'] != null && element['longitude'] != null) {
|
||||
markers.add(
|
||||
Marker(
|
||||
icon: _markerIcon!,
|
||||
markerId: MarkerId(doc.id),
|
||||
position: LatLng(
|
||||
element['latitude'],
|
||||
element['longitude'],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
print('error coordenadas $e');
|
||||
updateMarkersForServiceType(_serviceType);
|
||||
}
|
||||
|
||||
static CameraPosition initialCameraPosition = const CameraPosition(
|
||||
target: LatLng(7.8939100, -72.5078200),
|
||||
zoom: 14.4746,
|
||||
);
|
||||
|
||||
void setInitialCameraPosition(String coordsOfCity) {
|
||||
if (coordsOfCity != '0.0,0.0') {
|
||||
List<String> coords = coordsOfCity.split(',');
|
||||
double lat = double.parse(coords[0]);
|
||||
double lng = double.parse(coords[1]);
|
||||
|
||||
initialCameraPosition = CameraPosition(
|
||||
target: LatLng(lat, lng),
|
||||
zoom: 14.4746,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -758,6 +785,8 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
||||
_serviceType = serviceType;
|
||||
_serviceTypeController.text =
|
||||
_serviceType;
|
||||
|
||||
updateMarkersForServiceType(_serviceType);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user