geodesy 0.5.0
geodesy: ^0.5.0 copied to clipboard
A Dart library for geodesic and trigonometric calculations working with points and paths
Geodesy #
A Dart library for implementing geodesic and trigonometric calculations based on a spherical Earth model for working with points and paths such as distances, bearings and destinations
Getting Started #
Add the following line in your pubspec.yml
file #
geodesy:<latest_version>
Include the widget in your dart file #
import 'package:geodesy/geodesy.dart';
Usage #
Geodesy() #
final Geodesy geodesy = Geodesy();
LatLng(double latitude, double longitude) #
final LatLng l = LatLng(22.308, 114.1716);
Methods #
destinationPointByDistanceAndBearing(LatLng l, num distance, num bearing, [num radius]) #
Calculate a destination point given the distance and bearing. If radius is not specified, Earth radius will be used.
final LatLng destinationPoint = geodesy.destinationPointByDistanceAndBearing(l3, 2400, 420.2);
midPointBetweenTwoGeoPoints(LatLng l1, LatLng l2) #
Calculate the midpoint between teo geo points.
final LatLng midpoint = geodesy.midPointBetweenTwoGeoPoints(l1, l2);
distanceBetweenTwoGeoPoints(LatLng l1, LatLng l2, [num radius]) #
Calculate the distance in meters between two geo points. If radius is not specified, Earth radius will be used.
final num distance = geodesy.distanceBetweenTwoGeoPoints(l1, l2);
bearingBetweenTwoGeoPoints(LatLng l1, LatLng l2) #
Calculate the bearing from point l1 to point l2.
final num finalBearing = geodesy.finalBearingBetweenTwoGeoPoints(l1, l2);
finalBearingBetweenTwoGeoPoints(LatLng l1, LatLng l2) #
Calculate the final bearing from point l1 to point l2.
final num finalBearing = geodesy.finalBearingBetweenTwoGeoPoints(l1, l2);
degreesToRadians(num degrees) #
Convert degrees to radians
final num l1LatRadians = degreesToRadians(l1.lat);
radiansToDegrees(num radians) #
Convert degrees to radians
final num degrees = radiansToDegrees(latRadians);
isGeoPointInBoundingBox(LatLng l, LatLng topLeft, LatLng bottomRight) #
Check if a given geo point is in the bounding box
final bool inBoundingBox = geodesy.isGeoPointInBoundingBox(l1, l2, l3);
intersectionByPaths(LatLng l1, LatLng l2, num b1, num b2) #
Calculate the geo point of intersection of two given paths
final LatLng intersectionByPaths = geodesy.intersectionByPaths(l1, l2, b1, b2);
crossTrackDistanceTo(LatLng l1, LatLng start, LatLng end, [num radius]) #
Calculate signed distance from a geo point to create circle with start and end points
final num distanceToGreatCircle = geodesy.crossTrackDistanceTo(l1, l2, l3);
isGeoPointInPolygon(LatLng l, List #
Check if a given geo point is in the a polygon using even-odd rule algorithm
final bool isGeoPointInPolygon = geodesy.isGeoPointInPolygon(l, poly);
pointsInRange(LatLng point, List #
Get a list of points within a distance in meters from a given point
final point = LatLng(51.0, 0);
final pointsToCheck = <LatLng>[/* points here */];
final distance = 10000;
List<LatLng> geoFencedPoints = geodesy.pointsInRange(point, pointsToCheck, distance);
getRectangleBounds(List #
Similar to PolygonEnvelop in Python
List<LatLng> polygonCoords = [
const LatLng(37.7749, -122.4194),
const LatLng(37.3382, -121.8863),
const LatLng(37.7749, -121.4194),
const LatLng(37.7749, -123.4194),
];
List<LatLng> rectangleBounds = geodesy.getRectangleBounds(polygonCoords);
Great-circle distance between two points using the Haversine formula #
Calculate the Great-Circle Distance between two Geo points
num latitude1 = 37.7749;
num longitude1 = -122.4194;
num latitude2 = 37.3382;
num longitude2 = -121.8863;
num greatCircleDistance = geodesy.greatCircleDistanceBetweenTwoGeoPoints(
latitude1, longitude1, latitude2, longitude2);
calculateBoundingBox(LatLng centerPoint, num distanceInKm) #
Given the Latitude and Longitude and distance in kilometers it calculate the bounding box value
final centerPoint = const LatLng(
37.7749, -122.4194); // Example central position (San Francisco)
final distanceInKm = 1.0; // Example distance in kilometers
final boundingBox = geodesy.calculateBoundingBox(centerPoint, distanceInKm);