The Geodesy
class provides a collection of methods for performing various geodetic calculations, including distance calculations, point intersections, and more. This class is designed to work with geographical coordinates in the form of latitude and longitude.
final geodesy = Geodesy();
Call any function which is given below using geodesy Instance.
Calculate a destination point given an initial point, a distance, a bearing, and an optional radius.
LatLng destinationPointByDistanceAndBearing(
LatLng initialPoint, num distance, num bearing, [num? radius]
)
initialPoint
(LatLng): The initial geographical point (latitude, longitude).distance
(num): The distance in meters.bearing
(num): The bearing angle in degrees.radius
(num, optional): The Earth's radius (default isnull
).
Returns a LatLng
object representing the calculated destination point.
Calculate the geographical midpoint between two points.
LatLng midPointBetweenTwoGeoPoints(LatLng point1, LatLng point2)
point1
(LatLng): The first geographical point (latitude, longitude).point2
(LatLng): The second geographical point (latitude, longitude).
Returns a LatLng
object representing the midpoint between the two input points.
Calculate the intersection point of two paths defined by points and bearings.
LatLng? intersectionByPaths(
LatLng point1, LatLng point2, num bearing1, num bearing2
)
point1
(LatLng): The first geographical point (latitude, longitude).point2
(LatLng): The second geographical point (latitude, longitude).bearing1
(num): The bearing angle for the first path in degrees.bearing2
(num): The bearing angle for the second path in degrees.
Returns a LatLng
object representing the intersection point or null
if no intersection is found.
Calculate the distance in meters between two geographical points.
num distanceBetweenTwoGeoPoints(
LatLng point1, LatLng point2, [num? radius]
)
point1
(LatLng): The first geographical point (latitude, longitude).point2
(LatLng): The second geographical point (latitude, longitude).radius
(num, optional): The Earth's radius (default isnull
).
Returns the distance in meters between the two input points.
Calculate the bearing angle from one point to another.
num bearingBetweenTwoGeoPoints(LatLng fromPoint, LatLng toPoint)
fromPoint
(LatLng): The starting geographical point (latitude, longitude).toPoint
(LatLng): The target geographical point (latitude, longitude).
Returns the bearing angle in degrees from the starting point to the target point.
Calculate the final bearing angle from one point to another.
num finalBearingBetweenTwoGeoPoints(LatLng fromPoint, LatLng toPoint)
fromPoint
(LatLng): The starting geographical point (latitude, longitude).toPoint
(LatLng): The target geographical point (latitude, longitude).
Returns the final bearing angle in degrees from the starting point to the target point.
Calculate the signed distance from a point to a line defined by two other points.
num crossTrackDistanceTo(
LatLng point, LatLng start, LatLng end, [num? radius]
)
point
(LatLng): The point to calculate the distance from (latitude, longitude).start
(LatLng): The starting point of the line (latitude, longitude).end
(LatLng): The ending point of the line (latitude, longitude).radius
(num, optional): The Earth's radius (default isnull
).
Returns the signed cross-track distance in meters.
Check if a given point is within a bounding box defined by two corner points.
bool isGeoPointInBoundingBox(
LatLng point, LatLng topLeft, LatLng bottomRight
)
point
(LatLng): The point to check (latitude, longitude).topLeft
(LatLng): The top-left corner of the bounding box (latitude, longitude).bottomRight
(LatLng): The bottom-right corner of the bounding box (latitude, longitude).
Returns true
if the point is within the bounding box, otherwise false
.
Check if a given point is within a polygon using the even-odd rule algorithm.
bool isGeoPointInPolygon(LatLng point, List<LatLng> polygon)
point
(LatLng): The point to check (latitude, longitude).polygon
(List<LatLng>
): A list of vertices defining the polygon.
Returns true
if the point is within the polygon, otherwise false
.
Get a list of points within a certain distance from a given point.
List<LatLng> pointsInRange(LatLng point, List<LatLng> pointsToCheck, num distance)
point
(LatLng): The center point (latitude, longitude).pointsToCheck
(List<LatLng>
): List of points to check against.distance
(num): The maximum distance in meters.
Returns a list of LatLng
points within the specified distance from the center point.
Calculate the great-circle distance between two points using the Haversine formula.
num greatCircleDistanceBetweenTwoGeoPoints(
num lat1, num lon1, num lat2, num lon2
)
lat1
(num): Latitude of the first point.lon1
(num): Longitude of the first point.lat2
(num): Latitude of the second point.lon2
(num): Longitude of the second point.
Returns the great-circle distance in meters.
Get the bounding rectangle for a polygon defined by its vertices.
List<LatLng> getRectangleBounds(List<LatLng> polygonCoords)
polygonCoords
(List<LatLng>
): List of vertices defining the polygon.
Returns a list of LatLng
points representing the bounding rectangle's corners.
Calculate the bounding box around a point with a given distance.
List<LatLng> calculateBoundingBox(LatLng centerPoint, num distanceInKm)
centerPoint
(LatLng): The center point (latitude, longitude).distanceInKm
(num): The distance in kilometers.
Returns a list of LatLng
points representing the bounding box's corners.
Find the centroid of a polygon defined by its vertices.
LatLng findPolygonCentroid(List<LatLng> polygon)
polygon
(List<LatLng>
): List of vertices defining the polygon.
Returns a LatLng
object representing the centroid of the polygon.
Calculate the intersection of two polygons defined by their vertices.
List<LatLng> getPolygonIntersection(List<LatLng> polygon1, List<LatLng> polygon2)
polygon1
(List<LatLng>
): List of vertices defining the first polygon.polygon2
(List<LatLng>
): List of vertices defining the second polygon.
Returns a list of LatLng
points representing the intersection polygon.
final double calculatedDistance =
geodesy.vincentyDistance(point1.latitude, point1.longitude, point2.latitude, point2.longitude);
final calculatedArea = geodesy.calculatePolygonWithHolesArea(outerPolygon, holes);
double equirectangularDistance = geodesy.equirectangularDistance(firstPoint, secondPoint);
double sLCDdistance = geodesy.sphericalLawOfCosinesDistance(bGPoint, pFPoint);
LatLng destinationPoints = geodesy.calculateDestinationPoint(initialPoint, bearingDegrees, distanceKm);
LatLng midPointBetweenTwoPoints = geodesy.calculateMidpoint(bgPoint1, pFPoint2);
List<LatLng> arcPoints = geodesy.calculatePointsAlongGreatCircle(startPoint, endPoint, numPoints);
double length = PolyLine.calculatePolyLineLength(polyLinePoints);
double polygonArea = geodesy.calculatePolygonArea(polygonPoints);
LatLng? intersection = geodesy.calculateGeodesicLineIntersection(
start1, end1, start2, end2);