update
This commit is contained in:
@@ -110,11 +110,6 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
|||||||
|
|
||||||
late GoogleMapController googleMapController;
|
late GoogleMapController googleMapController;
|
||||||
|
|
||||||
static CameraPosition initialCameraPosition = const CameraPosition(
|
|
||||||
target: LatLng(7.8939100, -72.5078200),
|
|
||||||
zoom: 14.4746,
|
|
||||||
);
|
|
||||||
|
|
||||||
Set<Marker> markers = {};
|
Set<Marker> markers = {};
|
||||||
|
|
||||||
Future<Position> _determinePosition() async {
|
Future<Position> _determinePosition() async {
|
||||||
@@ -180,12 +175,22 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<DocumentSnapshot<Map<String, dynamic>>>>
|
Future<List<DocumentSnapshot<Map<String, dynamic>>>> getUsersWithActiveStatus(
|
||||||
getUsersWithActiveStatus() async {
|
String _serviceType) async {
|
||||||
var querySnapshot = await FirebaseFirestore.instance
|
var querySnapshot;
|
||||||
.collection('users')
|
|
||||||
.where('estado', isEqualTo: 'activo')
|
if (_serviceType != "Servicio") {
|
||||||
.get();
|
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;
|
return querySnapshot.docs;
|
||||||
}
|
}
|
||||||
@@ -199,6 +204,43 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
|||||||
|
|
||||||
String _ciudad = '...';
|
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
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@@ -229,21 +271,8 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
|||||||
.then((String s) {
|
.then((String s) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_coordsOfCity = s;
|
_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;
|
_markerIcon = icon;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
try {
|
|
||||||
getUsersWithActiveStatus().then((value) {
|
|
||||||
for (var doc in value) {
|
|
||||||
final element = doc.data()!;
|
|
||||||
|
|
||||||
if (element['latitude'] != null && element['longitude'] != null) {
|
updateMarkersForServiceType(_serviceType);
|
||||||
markers.add(
|
}
|
||||||
Marker(
|
|
||||||
icon: _markerIcon!,
|
static CameraPosition initialCameraPosition = const CameraPosition(
|
||||||
markerId: MarkerId(doc.id),
|
target: LatLng(7.8939100, -72.5078200),
|
||||||
position: LatLng(
|
zoom: 14.4746,
|
||||||
element['latitude'],
|
);
|
||||||
element['longitude'],
|
|
||||||
),
|
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]);
|
||||||
});
|
|
||||||
} catch (e) {
|
initialCameraPosition = CameraPosition(
|
||||||
print('error coordenadas $e');
|
target: LatLng(lat, lng),
|
||||||
|
zoom: 14.4746,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -758,6 +785,8 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
|||||||
_serviceType = serviceType;
|
_serviceType = serviceType;
|
||||||
_serviceTypeController.text =
|
_serviceTypeController.text =
|
||||||
_serviceType;
|
_serviceType;
|
||||||
|
|
||||||
|
updateMarkersForServiceType(_serviceType);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user