Implementation
static FlightLocation? vectorToLocation(
{required FlightLocation droneLocation,
required FlightLocation pointOfInterest,
required FlightVector vector}) {
final double azimuthToDestination;
final double destinationLatitude;
final double destinationLongitude;
if (droneLocation.latitude == pointOfInterest.latitude &&
droneLocation.longitude == pointOfInterest.longitude) {
developer.log(
'vectorToLocation - Waypoint Mission Point of Interest cannot be identical to the drone (home) location',
name: kLogKindDjiFlutterPlugin,
);
return null;
}
azimuthToDestination = 180 -
vector.headingRelativeToPointOfInterest -
(atan((droneLocation.latitude - pointOfInterest.latitude) /
(droneLocation.longitude - pointOfInterest.longitude)) *
180 /
pi);
// Latitude = North/South
double computedDestinationLatitude = pointOfInterest.latitude +
(vector.distanceFromPointOfInterest *
sin(azimuthToDestination * pi / 180) *
meterToDecimalDegree);
// Setting the Latitude precision to 8 decimals (~1.1mm accuracy, which is the GPS limit).
computedDestinationLatitude = computedDestinationLatitude * 100000000;
destinationLatitude = computedDestinationLatitude.round() / 100000000;
// Longitude = East/West
double computedDestinationLongitude = pointOfInterest.longitude +
(vector.distanceFromPointOfInterest *
cos(azimuthToDestination * pi / 180) *
meterToDecimalDegree);
// Setting the Latitude precision to 8 decimals (~1.1mm accuracy, which is the GPS limit).
computedDestinationLongitude = computedDestinationLongitude * 100000000;
destinationLongitude = computedDestinationLongitude.round() / 100000000;
developer.log(
'vectorToLocation - computed coordinates:',
name: kLogKindDjiFlutterPlugin,
);
developer.log(
'Latitude: $destinationLatitude',
name: kLogKindDjiFlutterPlugin,
);
developer.log(
'Longitude: $destinationLongitude',
name: kLogKindDjiFlutterPlugin,
);
developer.log(
'Altitude: ${vector.destinationAltitude}',
name: kLogKindDjiFlutterPlugin,
);
return FlightLocation(
latitude: destinationLatitude,
longitude: destinationLongitude,
altitude: vector.destinationAltitude);
}