updateUserLocation method

Future<void> updateUserLocation(
  1. String groupId,
  2. String userId,
  3. GeoPoint location, {
  4. double? speed,
  5. double? heading,
  6. double? accuracy,
})

Updates a user's location in a group

Implementation

Future<void> updateUserLocation(
  String groupId,
  String userId,
  GeoPoint location, {
  double? speed,
  double? heading,
  double? accuracy,
}) async {
  try {
    final data = {
      'location': location,
      'timestamp': FieldValue.serverTimestamp(),
    };

    // Add optional fields if provided
    if (speed != null) data['speed'] = speed;
    if (heading != null) data['heading'] = heading;
    if (accuracy != null) data['accuracy'] = accuracy;

    await _firestore
        .collection(_collectionPath)
        .doc(groupId)
        .collection(_locationSubcollection)
        .doc(userId)
        .update(data);
  } catch (e) {
    print('Error updating location: $e');
    rethrow;
  }
}