import 'dart:convert';
import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:intl/intl.dart';
import 'package:timeago/timeago.dart' as timeago;
import '/flutter_flow/lat_lng.dart';
import '/flutter_flow/place.dart';
import '/flutter_flow/uploaded_file.dart';
import '/flutter_flow/custom_functions.dart';
import '/backend/backend.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import '/auth/firebase_auth/auth_util.dart';
double calculateSpeed(
double lat1,
double long1,
double lat2,
double long2,
) {
/// MODIFY CODE ONLY BELOW THIS LINE
// Convert degrees to radians
lat1 = lat1 * pi / 180;
long1 = long1 * pi / 180;
lat2 = lat2 * pi / 180;
long2 = long2 * pi / 180;
double deltaLat = lat2 - lat1;
double deltaLong = long2 - long1;
double earthRadius = 6371; // Earth's radius in kilometers
// Haversine formula
double a = pow(sin(deltaLat / 2), 2) +
cos(lat1) * cos(lat2) * pow(sin(deltaLong / 2), 2);
double c = 2 * atan2(sqrt(a), sqrt(1 - a));
double distance = earthRadius * c;
// Assuming the time delta is 2 seconds, converting to hours
double timeDeltaHours = 2 / 3600;
double speed = distance / timeDeltaHours;
return speed; // Speed in km/h
/// MODIFY CODE ONLY ABOVE THIS LINE
}
Nothing is wrong with this function, yet FF won't run because it says there's an error in it:
1
3 replies