### Install flutter_map_math Package Source: https://context7.com/ujjwalsharma2210/flutter_map_math/llms.txt Add the flutter_map_math package to your pubspec.yaml file and run flutter pub get to install it. ```yaml dependencies: flutter_map_math: ^0.2.4 ``` -------------------------------- ### destinationPoint Source: https://github.com/ujjwalsharma2210/flutter_map_math/blob/main/README.md Calculates the geographical coordinates of a destination point given a starting point, distance, and bearing. ```APIDOC ## destinationPoint ### Description Calculates the destination point given a starting point, distance, and bearing. ### Method `FlutterMapMath.destinationPoint` ### Parameters - **startPoint** (LatLng) - The starting geographical coordinates. - **distance** (double) - The distance to travel in meters. - **bearing** (double) - The bearing in degrees. ### Returns - **destinationPoint** (LatLng) - The geographical coordinates of the destination point. ### Example ```dart LatLng startingPoint = LatLng(37.4219999, -122.0840575); double distance = 1000; double bearing = 90; LatLng destinationPoint = FlutterMapMath.destinationPoint(startingPoint, distance, bearing); ``` ``` -------------------------------- ### FlutterMapMath.destinationPoint Source: https://context7.com/ujjwalsharma2210/flutter_map_math/llms.txt Computes the destination LatLng given a starting latitude/longitude, a distance in meters, and a bearing in degrees. Useful for drawing range rings or projecting movement vectors. ```APIDOC ## FlutterMapMath.destinationPoint ### Description Computes the destination LatLng given a starting latitude/longitude, a distance in meters, and a bearing in degrees. Useful for drawing range rings or projecting movement vectors. ### Method ```dart static LatLng destinationPoint(double lat, double lon, double distance, double bearing) ``` ### Parameters #### Path Parameters - **lat** (double) - Required - Latitude of the starting point. - **lon** (double) - Required - Longitude of the starting point. - **distance** (double) - Required - The distance to travel in meters. - **bearing** (double) - Required - The bearing in degrees (0-360). ### Request Example ```dart import 'package:flutter_map_math/flutter_geo_math.dart'; import 'package:latlong2/latlong.dart'; void main() { LatLng destination = FlutterMapMath.destinationPoint( 37.4219999, -122.0840575, 1000, // meters 90, // bearing in degrees ); print('Destination: ${destination.latitude}, ${destination.longitude}'); } ``` ### Response #### Success Response (200) - **destination** (LatLng) - The calculated destination point. ``` -------------------------------- ### Calculate Destination Point Source: https://context7.com/ujjwalsharma2210/flutter_map_math/llms.txt Computes the destination LatLng given a starting latitude/longitude, a distance in meters, and a bearing in degrees. Useful for drawing range rings or projecting movement vectors. ```dart import 'package:flutter_map_math/flutter_geo_math.dart'; import 'package:latlong2/latlong.dart'; void main() { // Travel 1000 m due east (bearing = 90°) from Google HQ LatLng destination = FlutterMapMath.destinationPoint( 37.4219999, -122.0840575, 1000, // meters 90, // bearing in degrees ); print('Destination: ${destination.latitude}, ${destination.longitude}'); // ~37.422, -121.9706 } ``` -------------------------------- ### Calculate Intersection of Two Paths Source: https://github.com/ujjwalsharma2210/flutter_map_math/blob/main/example/example.md Calculates the intersection point of two paths defined by a starting point and a bearing. ```APIDOC ## calculateIntersection ### Description Calculates the intersection point of two paths defined by a starting point and a bearing. ### Method `calculateIntersection(double lat1, double lon1, double bearing1, double lat2, double lon2, double bearing2)` ### Parameters - **lat1** (double) - Latitude of the starting point for the first path. - **lon1** (double) - Longitude of the starting point for the first path. - **bearing1** (double) - Bearing in degrees for the first path. - **lat2** (double) - Latitude of the starting point for the second path. - **lon2** (double) - Longitude of the starting point for the second path. - **bearing2** (double) - Bearing in degrees for the second path. ### Response Example ```dart double lat1 = 40.7128; // New York City double lon1 = -74.0060; double bearing1 = 45.0; // Degrees double lat2 = 51.5074; // London double lon2 = -0.1278; double bearing2 = 180.0; // Degrees LatLng intersection = calculateIntersection(lat1, lon1, bearing1, lat2, lon2, bearing2); ``` ``` -------------------------------- ### calculateIntersection Source: https://github.com/ujjwalsharma2210/flutter_map_math/blob/main/README.md Calculates the intersection point of two lines defined by a starting point and a bearing. ```APIDOC ## calculateIntersection ### Description Calculates the intersection point of two lines on the map, each defined by a starting point and a bearing. ### Method `FlutterMapMath.calculateIntersection` ### Parameters - **location1** (LatLng) - The starting point of the first line. - **bearing1** (double) - The bearing of the first line in degrees. - **location2** (LatLng) - The starting point of the second line. - **bearing2** (double) - The bearing of the second line in degrees. ### Returns - **intersection** (LatLng) - The geographical coordinates of the intersection point. ### Example ```dart LatLng location1 = LatLng(40.7128, -74.0060); // New York City double bearing1 = 45.0; // Degrees LatLng location2 = LatLng(51.5074, -0.1278); // London double bearing2 = 180.0; // Degrees LatLng intersection = FlutterMapMath.calculateIntersection(location1, bearing1, location2, bearing2); ``` ``` -------------------------------- ### Calculate Intersection of Two Lines Source: https://github.com/ujjwalsharma2210/flutter_map_math/blob/main/README.md Finds the intersection point of two lines defined by a starting point and a bearing for each line. Requires the starting coordinates and bearing in degrees for both lines. ```dart LatLng location1 = LatLng(40.7128, -74.0060); // New York City double bearing1 = 45.0; // Degrees LatLng location2 = LatLng(51.5074, -0.1278); // London double bearing2 = 180.0; // Degrees LatLng intersection = FlutterMapMath.calculateIntersection(location1, bearing1, location2, bearing2); ``` -------------------------------- ### Calculate Destination Point Source: https://github.com/ujjwalsharma2210/flutter_map_math/blob/main/example/example.md Calculates the geographical coordinates of a point given a starting point, distance, and bearing. ```APIDOC ## destinationPoint ### Description Calculates the geographical coordinates of a point given a starting point, distance, and bearing. ### Method `FlutterMapMath.destinationPoint(LatLng start, double distance, double bearing)` ### Parameters - **start** (LatLng) - The starting geographical coordinates. - **distance** (double) - The distance to travel (in meters). - **bearing** (double) - The initial bearing in degrees (0 is North, 90 is East). ### Response Example ```dart LatLng startingPoint = LatLng(37.4219999, -122.0840575); double distance = 1000; double bearing = 90; LatLng destinationPoint = FlutterMapMath.destinationPoint(startingPoint, distance, bearing); ``` ``` -------------------------------- ### Calculate Destination Point Source: https://github.com/ujjwalsharma2210/flutter_map_math/blob/main/example/example.md Determine the geographical coordinates of a destination point given a starting point, a distance in meters, and an initial bearing in degrees. ```dart LatLng startingPoint = LatLng(37.4219999, -122.0840575); double distance = 1000; double bearing = 90; LatLng destinationPoint = FlutterMapMath.destinationPoint(startingPoint, distance, bearing); ``` -------------------------------- ### Get Elevation for a Location Source: https://github.com/ujjwalsharma2210/flutter_map_math/blob/main/README.md Fetches the elevation in meters for a given LatLng location using the Open-Elevation API. Returns a Future. Ensure the latlong2 and flutter_map_math packages are imported. ```dart import 'package:flutter_map_math/flutter_geo_math.dart'; import 'package:latlong2/latlong.dart'; void testElevation() async { LatLng location = LatLng(27.9881, 86.9250); // Everest Base Camp double? elevation = await FlutterMapMath.getElevation(location); print("Elevation: $elevation meters"); } void main() { testElevation(); } ``` -------------------------------- ### FlutterMapMath.calculateIntersection Source: https://context7.com/ujjwalsharma2210/flutter_map_math/llms.txt Finds the intersection point of two great-circle paths, each defined by a starting LatLng and a bearing. Throws an Exception if the paths are parallel (distance between origins is zero). ```APIDOC ## FlutterMapMath.calculateIntersection ### Description Finds the intersection point of two great-circle paths, each defined by a starting LatLng and a bearing. Throws an Exception if the paths are parallel (distance between origins is zero). ### Method ```dart static LatLng calculateIntersection(LatLng start1, double bearing1, LatLng start2, double bearing2) ``` ### Parameters #### Path Parameters - **start1** (LatLng) - Required - The starting point of the first path. - **bearing1** (double) - Required - The bearing of the first path in degrees (0-360). - **start2** (LatLng) - Required - The starting point of the second path. - **bearing2** (double) - Required - The bearing of the second path in degrees (0-360). ### Request Example ```dart import 'package:flutter_map_math/flutter_geo_math.dart'; import 'package:latlong2/latlong.dart'; void main() { LatLng newYork = LatLng(40.7128, -74.0060); LatLng london = LatLng(51.5074, -0.1278); try { LatLng intersection = FlutterMapMath.calculateIntersection( newYork, 45.0, // heading NE from NYC london, 180.0, // heading south from London ); print('Intersection: ${intersection.latitude}, ${intersection.longitude}'); } catch (e) { print('Error: $e'); } } ``` ### Response #### Success Response (200) - **intersection** (LatLng) - The calculated intersection point. #### Error Response - **Exception** - Thrown if the paths are parallel. ``` -------------------------------- ### Calculate Intersection of Two Great-Circle Paths Source: https://context7.com/ujjwalsharma2210/flutter_map_math/llms.txt Finds the intersection point of two great-circle paths. Each path is defined by a starting LatLng and a bearing. Throws an Exception if the paths are parallel. ```dart import 'package:flutter_map_math/flutter_geo_math.dart'; import 'package:latlong2/latlong.dart'; void main() { LatLng newYork = LatLng(40.7128, -74.0060); LatLng london = LatLng(51.5074, -0.1278); try { LatLng intersection = FlutterMapMath.calculateIntersection( newYork, 45.0, // heading NE from NYC london, 180.0, // heading south from London ); print('Intersection: ${intersection.latitude}, ${intersection.longitude}'); } catch (e) { print('Error: $e'); // "Lines are parallel, intersection is undefined." } } ``` -------------------------------- ### Calculate Intersection of Two Geodesic Lines Source: https://github.com/ujjwalsharma2210/flutter_map_math/blob/main/example/example.md This function calculates the intersection point of two geodesic lines defined by their starting points and bearings. Ensure correct LatLng and bearing values are provided. ```dart double lat1 = 40.7128; // New York City double lon1 = -74.0060; double bearing1 = 45.0; // Degrees double lat2 = 51.5074; // London double lon2 = -0.1278; double bearing2 = 180.0; // Degrees LatLng intersection = calculateIntersection(lat1, lon1, bearing1, lat2, lon2, bearing2); ``` -------------------------------- ### K-Means Clustering for LatLng Points Source: https://github.com/ujjwalsharma2210/flutter_map_math/blob/main/README.md Demonstrates how to use the KMeans class to partition a list of LatLng points into a specified number of clusters. Requires k, maxIterations, and tolerance for initialization. ```dart List mapPoints = [ LatLng(1.0, 1.0), LatLng(2.0, 2.0), LatLng(2.1, 2.2), LatLng(4.0, 4.0), LatLng(6.0, 6.0), LatLng(8.0, 8.0), ]; // Instantiate the KMeans clustering algorithm with k = 3 clusters, // a maximum of 100 iterations, and a convergence tolerance of 1 meter. KMeans kmeans = KMeans(k: 3, maxIterations: 100, tolerance: 1.0); // Perform clustering. List> clusters = kmeans.cluster(points); // Print the clusters. for (int i = 0; i < clusters.length; i++) { print('Cluster ${i + 1}:'); for (var point in clusters[i]) { print(' (${point.latitude.toStringAsFixed(4)}, ${point.longitude.toStringAsFixed(4)})'); } print('---------------------'); } ``` -------------------------------- ### Order Points by Reachability with OPTICS Source: https://context7.com/ujjwalsharma2210/flutter_map_math/llms.txt Produces an ordered list of points based on reachability distance, preserving density structure. Instantiate with an epsilon radius (meters) and minimum points. ```dart import 'package:flutter_map_math/flutter_cluster.dart'; import 'package:latlong2/latlong.dart'; void main() { List mapPoints = [ LatLng(1.0, 1.0), LatLng(2.0, 2.0), LatLng(2.1, 2.2), LatLng(4.0, 4.0), LatLng(6.0, 6.0), LatLng(8.0, 8.0), ]; OPTICS optics = OPTICS(500, 2); // 500 m radius, min 2 points List orderedPoints = optics.optics(mapPoints); print('Ordered ${orderedPoints.length} points by reachability:'); for (var point in orderedPoints) { print(' Lat: ${point.latitude.toStringAsFixed(4)}, ' 'Lng: ${point.longitude.toStringAsFixed(4)}'); } } ``` -------------------------------- ### Import Flutter Map Math Package Source: https://github.com/ujjwalsharma2210/flutter_map_math/blob/main/README.md Import the package to access its utility functions in your Dart code. ```dart import 'package:flutter_map_math/flutter_map_math.dart'; ``` -------------------------------- ### Partition Points into K Clusters with KMeans Source: https://context7.com/ujjwalsharma2210/flutter_map_math/llms.txt Partitions geospatial points into a specified number of clusters (k) using spherical K-means. Convergence is based on a tolerance in meters. Returns a list of lists, where each inner list represents a cluster. ```dart import 'package:flutter_map_math/flutter_cluster.dart'; import 'package:latlong2/latlong.dart'; void main() { List points = [ LatLng(37.7749, -122.4194), // San Francisco LatLng(37.8044, -122.2711), // Oakland LatLng(37.6879, -122.4702), // Daly City LatLng(34.0522, -118.2437), // Los Angeles LatLng(36.1699, -115.1398), // Las Vegas LatLng(40.7128, -74.0060), // New York City LatLng(42.3601, -71.0589), // Boston LatLng(41.8781, -87.6298), // Chicago LatLng(29.7604, -95.3698), // Houston LatLng(25.7617, -80.1918), // Miami ]; KMeans kmeans = KMeans(k: 3, maxIterations: 100, tolerance: 1.0); List> clusters = kmeans.cluster(points); for (int i = 0; i < clusters.length; i++) { print('Cluster ${i + 1} (${clusters[i].length} points):'); for (var p in clusters[i]) { print(' (${p.latitude.toStringAsFixed(4)}, ${p.longitude.toStringAsFixed(4)})'); } print('---'); } // Expected: roughly West Coast, South/East, and Midwest/Northeast groups } ``` -------------------------------- ### Clustering with OPTICS Source: https://github.com/ujjwalsharma2210/flutter_map_math/blob/main/README.md Implements the OPTICS clustering algorithm, which produces an ordered list of points based on reachability distance. Useful for identifying nested clusters and dynamic density thresholding. ```dart List mapPoints = [ LatLng(1.0, 1.0), LatLng(2.0, 2.0), LatLng(2.1, 2.2), LatLng(4.0, 4.0), LatLng(6.0, 6.0), LatLng(8.0, 8.0), ]; OPTICS optics = OPTICS(500, 2); // 500m radius, min 2 points List clusterOrder = optics.optics(mapPoints); print("Ordered Points:"); for (var point in clusterOrder) { print("Lat: ${point.latitude}, Lng: ${point.longitude}"); } ``` -------------------------------- ### Generate Heatmap Grid from Points Source: https://context7.com/ujjwalsharma2210/flutter_map_math/llms.txt Generates a 2D heatmap grid from a list of `HeatPoint` objects using a Gaussian kernel. Requires specifying points, influence radius, and grid resolution. Returns a map of grid cells to accumulated intensity. ```dart import 'dart:math'; import 'package:flutter_map_math/heat_map.dart'; import 'package:flutter_map_math/utils/models/heat_point.dart'; void main() { final points = [ HeatPoint(28.6139, 77.2090, 1.5), // New Delhi — high intensity HeatPoint(28.6140, 77.2091), // nearby — default intensity 1.0 HeatPoint(28.6150, 77.2100, 0.5), // slightly further — low intensity ]; final heatGrid = HeatmapGenerator.generateHeatmap( points: points, radius: 300, // influence radius in meters resolution: 50, // grid cell size in meters ); // Find the hottest cell Point? hotCell; double maxIntensity = 0; heatGrid.forEach((cell, intensity) { if (intensity > maxIntensity) { maxIntensity = intensity; hotCell = cell; } }); print('Total grid cells: ${heatGrid.length}'); print('Hottest cell: (${hotCell?.x}, ${hotCell?.y}) → ${maxIntensity.toStringAsFixed(2)}'); // Print all cells heatGrid.forEach((cell, intensity) { print('(${cell.x}, ${cell.y}) → ${intensity.toStringAsFixed(2)}'); }); // Sample output: // (-5, 0) → 0.41 // (-4, -3) → 0.46 // (-4, 0) → 0.75 } ``` -------------------------------- ### OPTICS Clustering Source: https://github.com/ujjwalsharma2210/flutter_map_math/blob/main/example/example.md Applies the OPTICS (Ordering Points To Identify the Clustering Structure) algorithm to order points based on density reachability. Requires defining a radius (`eps`) and minimum number of points (`minPoints`). ```dart import 'package:flutter_map_math/flutter_cluster.dart'; List mapPoints = [ LatLng(1.0, 1.0), LatLng(2.0, 2.0), LatLng(2.1, 2.2), LatLng(4.0, 4.0), LatLng(6.0, 6.0), LatLng(8.0, 8.0), ]; OPTICS optics = OPTICS(500, 2); // 500m radius, min 2 points List clusterOrder = optics.optics(mapPoints); print("Ordered Points:"); for (var point in clusterOrder) { print("Lat: ${point.latitude}, Lng: ${point.longitude}"); } ``` -------------------------------- ### OPTICS Clustering Source: https://github.com/ujjwalsharma2210/flutter_map_math/blob/main/example/example.md Performs OPTICS clustering to create a density-based ordering of points. ```APIDOC ## optics ### Description Performs OPTICS clustering to create a density-based ordering of points. ### Method `OPTICS(double maxRadius, int minPoints).optics(List points)` ### Parameters - **maxRadius** (double) - The maximum radius (in meters) to consider for neighborhood. - **minPoints** (int) - The minimum number of points required to form a dense region. - **points** (List) - A list of geographical points to cluster. ### Response Example ```dart List mapPoints = [ LatLng(1.0, 1.0), LatLng(2.0, 2.0), LatLng(2.1, 2.2), LatLng(4.0, 4.0), LatLng(6.0, 6.0), LatLng(8.0, 8.0), ]; OPTICS optics = OPTICS(500, 2); // 500m radius, min 2 points List clusterOrder = optics.optics(mapPoints); print("Ordered Points:"); for (var point in clusterOrder) { print("Lat: \'${point.latitude}\', Lng: \'${point.longitude}\'"); } ``` ``` -------------------------------- ### K-Means Clustering Source: https://github.com/ujjwalsharma2210/flutter_map_math/blob/main/example/example.md Performs K-Means clustering to partition data points into k clusters. ```APIDOC ## cluster ### Description Performs K-Means clustering to partition data points into k clusters. ### Method `KMeans(int k, {int maxIterations, double tolerance}).cluster(List points)` ### Parameters - **k** (int) - The number of clusters to form. - **maxIterations** (int, optional) - The maximum number of iterations to perform. - **tolerance** (double, optional) - The convergence tolerance, measured in meters. - **points** (List) - A list of geographical points to cluster. ### Response Example ```dart List points = [ LatLng(37.7749, -122.4194), // San Francisco LatLng(37.8044, -122.2711), // Oakland LatLng(37.6879, -122.4702), // Daly City LatLng(34.0522, -118.2437), // Los Angeles LatLng(36.1699, -115.1398), // Las Vegas LatLng(40.7128, -74.0060), // New York City LatLng(42.3601, -71.0589), // Boston LatLng(41.8781, -87.6298), // Chicago LatLng(29.7604, -95.3698), // Houston LatLng(25.7617, -80.1918), // Miami ]; KMeans kmeans = KMeans(k: 3, maxIterations: 100, tolerance: 1.0); List> clusters = kmeans.cluster(points); ``` ``` -------------------------------- ### FlutterMapMath.getElevation Source: https://context7.com/ujjwalsharma2210/flutter_map_math/llms.txt Asynchronously fetches the elevation (in meters) of a point using the Open-Elevation API. ```APIDOC ## FlutterMapMath.getElevation ### Description Asynchronously fetches the elevation (in meters) of a point using the [Open-Elevation API](https://api.open-elevation.com). Returns `null` on a non-200 HTTP response. ### Parameters - **latLng** (LatLng) - The geographical coordinates for which to retrieve elevation. ### Returns - (Future) - A future that resolves to the elevation in meters, or `null` if the data could not be retrieved. ``` -------------------------------- ### Calculate Distance and Bearing Between Two Points Source: https://github.com/ujjwalsharma2210/flutter_map_math/blob/main/example/example.md Use `distanceBetween` to find the distance in meters between two geographical points. Use `bearingBetween` to calculate the initial bearing from the first point to the second. ```dart double distance = FlutterMapMath.distanceBetween( 37.4219999, -122.0840575, 37.4220011, -122.0866519, "meters" ); double bearing = FlutterMapMath.bearingBetween( 37.4219999, -122.0840575, 37.4220011, -122.0866519, ); ``` -------------------------------- ### K-Means Clustering Source: https://github.com/ujjwalsharma2210/flutter_map_math/blob/main/example/example.md Performs K-Means clustering on a list of points, grouping them into a specified number of clusters (`k`). Parameters include `maxIterations` and `tolerance` for convergence. ```dart import 'package:flutter_map_math/flutter_cluster.dart'; List points = [ LatLng(37.7749, -122.4194), // San Francisco LatLng(37.8044, -122.2711), // Oakland LatLng(37.6879, -122.4702), // Daly City LatLng(34.0522, -118.2437), // Los Angeles LatLng(36.1699, -115.1398), // Las Vegas LatLng(40.7128, -74.0060), // New York City LatLng(42.3601, -71.0589), // Boston LatLng(41.8781, -87.6298), // Chicago LatLng(29.7604, -95.3698), // Houston LatLng(25.7617, -80.1918), // Miami ]; // Instantiate the KMeans clustering algorithm with k = 3 clusters, // a maximum of 100 iterations, and a convergence tolerance of 1 meter. KMeans kmeans = KMeans(k: 3, maxIterations: 100, tolerance: 1.0); // Perform clustering. List> clusters = kmeans.cluster(points); ``` -------------------------------- ### OPTICS Class Source: https://context7.com/ujjwalsharma2210/flutter_map_math/llms.txt The OPTICS class produces an ordered list of points by reachability distance, preserving the hierarchical density structure of the dataset. Instantiate with an epsilon radius (meters) and minimum points. ```APIDOC ## OPTICS (class) The `OPTICS` class produces an ordered list of points by reachability distance, preserving the hierarchical density structure of the dataset. Instantiate with an epsilon radius (meters) and minimum points. ### Constructor `OPTICS(double epsilon, int minPoints)` - `epsilon` (double): The maximum distance between two samples for one to be considered as in the neighborhood of the other. - `minPoints` (int): The number of samples in a neighborhood for a point to be considered as a core point. ### Method `List optics(List points)` - `points` (List): The list of points to process. ### Returns - `List`: An ordered list of points by reachability distance. ``` -------------------------------- ### Create Boundary Checker Source: https://github.com/ujjwalsharma2210/flutter_map_math/blob/main/example/example.md Creates a function that checks if a given point is within a circular boundary defined by a center and radius. ```APIDOC ## createBoundary ### Description Creates a function that checks if a given point is within a circular boundary defined by a center and radius. ### Method `createBoundary(LatLng center, double radiusInMeters)` ### Parameters - **center** (LatLng) - The center coordinates of the boundary. - **radiusInMeters** (double) - The radius of the boundary in meters. ### Returns A function that takes a `LatLng` point and returns `true` if the point is within the boundary, `false` otherwise. ### Response Example ```dart LatLng center = LatLng(37.4219983, -122.084); double radiusInMeters = 100.0; Function isInBoundary = createBoundary(center, radiusInMeters); LatLng userLocation = LatLng(37.422, -122.083); bool isWithinBoundary = isInBoundary(userLocation); ``` ``` -------------------------------- ### Calculate Bearing Between Two Points Source: https://github.com/ujjwalsharma2210/flutter_map_math/blob/main/example/example.md Calculates the initial bearing (direction) from the first point to the second point. ```APIDOC ## bearingBetween ### Description Calculates the initial bearing from the first point to the second point. ### Method `FlutterMapMath.bearingBetween(double lat1, double lon1, double lat2, double lon2)` ### Parameters - **lat1** (double) - Latitude of the starting point. - **lon1** (double) - Longitude of the starting point. - **lat2** (double) - Latitude of the destination point. - **lon2** (double) - Longitude of the destination point. ### Response Example ```dart double bearing = FlutterMapMath.bearingBetween(37.4219999, -122.0840575, 37.4220011, -122.0866519); ``` ``` -------------------------------- ### Fetch Elevation Data Asynchronously Source: https://context7.com/ujjwalsharma2210/flutter_map_math/llms.txt Asynchronously fetches the elevation in meters for a given `LatLng` point using the Open-Elevation API. Returns `null` if the API request fails. Requires `flutter_map_math` and `latlong2`. ```dart import 'package:flutter_map_math/flutter_geo_math.dart'; import 'package:latlong2/latlong.dart'; void main() async { LatLng everestBasecamp = LatLng(27.9881, 86.9250); double? elevation = await FlutterMapMath.getElevation(everestBasecamp); if (elevation != null) { print('Elevation: $elevation meters'); // ~5364 m } else { print('Failed to retrieve elevation data.'); } } ``` -------------------------------- ### Create Circular Boundary Checker Source: https://context7.com/ujjwalsharma2210/flutter_map_math/llms.txt Generates a reusable closure to check if a `LatLng` point falls within a circular geofence defined by a center and radius in meters. Requires `flutter_map_math` and `latlong2`. ```dart import 'package:flutter_map_math/flutter_geo_math.dart'; import 'package:latlong2/latlong.dart'; void main() { LatLng center = LatLng(37.4219983, -122.084); double radiusInMeters = 100.0; // Create the boundary checker once Function isInBoundary = FlutterMapMath.createBoundary(center, radiusInMeters); LatLng userA = LatLng(37.422, -122.083); LatLng userB = LatLng(37.500, -122.500); print('User A inside: ${isInBoundary(userA)}'); // true print('User B inside: ${isInBoundary(userB)}'); // false } ``` -------------------------------- ### Create and Check Geographical Boundary Source: https://github.com/ujjwalsharma2210/flutter_map_math/blob/main/example/example.md Generates a boundary checking function based on a center point and radius in meters. The returned function `isInBoundary` takes a `LatLng` and returns `true` if the point is within the boundary, `false` otherwise. ```dart LatLng center = LatLng(37.4219983, -122.084); double radiusInMeters = 100.0; Function isInBoundary = createBoundary(center, radiusInMeters); LatLng userLocation = LatLng(37.422, -122.083); bool isWithinBoundary = isInBoundary(userLocation); ``` -------------------------------- ### FlutterMapMath.bearingBetween Source: https://context7.com/ujjwalsharma2210/flutter_map_math/llms.txt Returns the forward azimuth (bearing) in degrees (0–360) from point 1 to point 2, measured clockwise from true north. ```APIDOC ## FlutterMapMath.bearingBetween ### Description Returns the forward azimuth (bearing) in degrees (0–360) from point 1 to point 2, measured clockwise from true north. ### Method ```dart static double bearingBetween(double lat1, double lon1, double lat2, double lon2) ``` ### Parameters #### Path Parameters - **lat1** (double) - Required - Latitude of the origin point. - **lon1** (double) - Required - Longitude of the origin point. - **lat2** (double) - Required - Latitude of the destination point. - **lon2** (double) - Required - Longitude of the destination point. ### Request Example ```dart import 'package:flutter_map_math/flutter_geo_math.dart'; void main() { double bearing = FlutterMapMath.bearingBetween( 37.4219999, -122.0840575, // origin 37.4220011, -122.0866519, // destination ); print('Bearing: $bearing°'); } ``` ### Response #### Success Response (200) - **bearing** (double) - The calculated bearing in degrees (0-360). ``` -------------------------------- ### Calculate Bearing Between Two Points Source: https://github.com/ujjwalsharma2210/flutter_map_math/blob/main/README.md Calculates the initial bearing (direction) from the first point to the second point in degrees. ```dart double bearing = FlutterMapMath.bearingBetween( 37.4219999, -122.0840575, 37.4220011, -122.0866519, ); ``` -------------------------------- ### HeatmapGenerator.generateHeatmap Source: https://context7.com/ujjwalsharma2210/flutter_map_math/llms.txt Generates a discrete 2D heatmap grid from a list of `HeatPoint` objects using a Gaussian kernel. Each `HeatPoint` carries a latitude, longitude, and optional intensity (default `1.0`). Returns a `Map, double>` mapping grid cells to accumulated weighted intensity. ```APIDOC ## HeatmapGenerator.generateHeatmap Generates a discrete 2D heatmap grid from a list of `HeatPoint` objects using a Gaussian kernel. Each `HeatPoint` carries a latitude, longitude, and optional intensity (default `1.0`). Returns a `Map, double>` mapping grid cells to accumulated weighted intensity. ### Parameters - `points` (List): The list of points to generate the heatmap from. - `radius` (double): The influence radius in meters for each point. - `resolution` (double): The size of each grid cell in meters. ### Returns - `Map, double>`: A map where keys are grid cell coordinates (`Point`) and values are the accumulated weighted intensity for that cell. ``` -------------------------------- ### bearingBetween Source: https://github.com/ujjwalsharma2210/flutter_map_math/blob/main/README.md Calculates the bearing between two geographical points. ```APIDOC ## bearingBetween ### Description Calculates the initial bearing (azimuth) from the first point to the second point. ### Method `FlutterMapMath.bearingBetween` ### Parameters - **lat1** (double) - Latitude of the starting point. - **lng1** (double) - Longitude of the starting point. - **lat2** (double) - Latitude of the destination point. - **lng2** (double) - Longitude of the destination point. ### Returns - **bearing** (double) - The bearing in degrees, ranging from -180 to 180. ### Example ```dart double bearing = FlutterMapMath.bearingBetween( 37.4219999, -122.0840575, 37.4220011, -122.0866519, ); ``` ``` -------------------------------- ### FlutterMapMath.createBoundary Source: https://context7.com/ujjwalsharma2210/flutter_map_math/llms.txt Creates a reusable closure that checks if a given LatLng falls within a circular boundary (geofence) defined by a center point and a radius in meters. ```APIDOC ## FlutterMapMath.createBoundary ### Description Creates a reusable closure that checks whether any given `LatLng` falls within a circular boundary (geofence) defined by a center point and a radius in meters. ### Parameters - **center** (LatLng) - The center point of the circular boundary. - **radiusInMeters** (double) - The radius of the circular boundary in meters. ### Returns - (Function) - A closure that accepts a `LatLng` object and returns `true` if the point is within the boundary, `false` otherwise. ``` -------------------------------- ### Generate Heatmap Intensities Source: https://github.com/ujjwalsharma2210/flutter_map_math/blob/main/README.md Generates a heatmap intensity map from a list of HeatPoint objects. Parameters include radius and resolution. The output maps cell coordinates to intensity values. ```dart import 'package:flutter_map_math/heat_map.dart'; import 'package:flutter_map_math/utils/models/heat_point.dart'; final points = [ HeatPoint(28.6139, 77.2090), HeatPoint(28.6140, 77.2091), HeatPoint(28.6150, 77.2100), ]; final heat = HeatmapGenerator.generateHeatmap( points: points, radius: 300, resolution: 50, ); heat.forEach((cell, intensity) { print('(${cell.x}, ${cell.y}) → ${intensity.toStringAsFixed(2)}'); }); ``` -------------------------------- ### KMeans Class Source: https://context7.com/ujjwalsharma2210/flutter_map_math/llms.txt The KMeans class partitions geospatial points into `k` clusters using spherical K-means with Cartesian centroid averaging. Convergence is determined by a tolerance in meters. Returns a `List>`. ```APIDOC ## KMeans (class) The `KMeans` class partitions geospatial points into `k` clusters using spherical K-means with Cartesian centroid averaging. Convergence is determined by a tolerance in meters. Returns a `List>`. ### Constructor `KMeans({required int k, int maxIterations = 100, double tolerance = 1.0})` - `k` (int): The number of clusters to form. - `maxIterations` (int): The maximum number of iterations to perform. - `tolerance` (double): The convergence tolerance in meters. ### Method `List> cluster(List points)` - `points` (List): The list of points to cluster. ### Returns - `List>`: A list of clusters, where each cluster is a list of `LatLng` points. ``` -------------------------------- ### Detect Proximity Source: https://github.com/ujjwalsharma2210/flutter_map_math/blob/main/example/example.md Finds points within a specified distance threshold from a user's location. ```APIDOC ## detectProximity ### Description Finds points within a specified distance threshold from a user's location. ### Method `FlutterMapMath.detectProximity(LatLng userLocation, List mapPoints, double distanceThreshold)` ### Parameters - **userLocation** (LatLng) - The reference point (e.g., user's current location). - **mapPoints** (List) - A list of geographical points to check. - **distanceThreshold** (double) - The maximum distance (in meters) to consider a point as nearby. ### Response Example ```dart LatLng userLocation = LatLng(3.0, 5.0); List mapPoints = [ LatLng(1.0, 1.0), LatLng(2.0, 2.0), LatLng(4.0, 4.0), LatLng(6.0, 6.0), LatLng(8.0, 8.0), ]; double distanceThreshold = 3.0; List nearbyPoints = FlutterMapMath.detectProximity(userLocation, mapPoints, distanceThreshold); ``` ``` -------------------------------- ### DBSCAN Clustering Source: https://github.com/ujjwalsharma2210/flutter_map_math/blob/main/example/example.md Performs Density-Based Spatial Clustering of Applications with Noise (DBSCAN) on a list of points. `eps` is the maximum distance to consider neighbors, and `minPoints` is the minimum number of points to form a dense region. ```dart import 'package:flutter_map_math/flutter_cluster.dart'; final points = [ LatLng(37.7749, -122.4194), // San Francisco LatLng(37.7750, -122.4195), // Near San Francisco LatLng(37.8044, -122.2711), // Oakland LatLng(37.8045, -122.2712), // Near Oakland LatLng(37.6879, -122.4702), // Daly City ]; // Define the parameters. // eps: maximum distance (in meters) to be considered neighbors. // minPoints: minimum number of points to form a dense region. const double eps = 100; // 100 meters const int minPoints = 2; // DBSCAN example. final clustersDBSCAN = FlutterCluster.dbscan(points, eps, minPoints); ``` -------------------------------- ### Project and Unproject LatLng to Mercator Source: https://context7.com/ujjwalsharma2210/flutter_map_math/llms.txt Converts `LatLng` coordinates to Web Mercator `Point` (in meters) and vice versa. Useful for 2D map rendering and coordinate math. Requires `flutter_map_math`, `latlong2`, and `dart:math`. ```dart import 'dart:math'; import 'package:flutter_map_math/flutter_geo_math.dart'; import 'package:latlong2/latlong.dart'; void main() { LatLng sanFrancisco = LatLng(37.7749, -122.4194); // Project to Mercator Point projected = FlutterMapMath.projectMercator(sanFrancisco); print('Mercator X: ${projected.x.toStringAsFixed(2)}'); print('Mercator Y: ${projected.y.toStringAsFixed(2)}'); // X: -13627665.27, Y: 4548672.36 // Unproject back to LatLng LatLng restored = FlutterMapMath.unprojectMercator(projected); print('Restored: ${restored.latitude.toStringAsFixed(4)}, ${restored.longitude.toStringAsFixed(4)}'); // 37.7749, -122.4194 } ``` -------------------------------- ### FlutterMapMath.projectMercator / unprojectMercator Source: https://context7.com/ujjwalsharma2210/flutter_map_math/llms.txt Converts LatLng coordinates to Web Mercator (EPSG:3857) Point and back, useful for 2D map rendering. ```APIDOC ## FlutterMapMath.projectMercator / unprojectMercator ### Description Converts a `LatLng` coordinate to Web Mercator (EPSG:3857) `Point` in meters and back. Useful for 2D tile-based map rendering and coordinate math in pixel space. ### FlutterMapMath.projectMercator #### Parameters - **latLng** (LatLng) - The geographical coordinates to project. #### Returns - (Point) - The projected point in Web Mercator coordinates (meters). ### FlutterMapMath.unprojectMercator #### Parameters - **point** (Point) - The Web Mercator coordinates to unproject. #### Returns - (LatLng) - The unprojected geographical coordinates. ``` -------------------------------- ### FlutterMapMath.distanceBetween Source: https://context7.com/ujjwalsharma2210/flutter_map_math/llms.txt Calculates the geodesic distance between two latitude/longitude points on Earth using the Haversine formula. Supported unit strings are "meters", "kilometers", "miles", and "yards". ```APIDOC ## FlutterMapMath.distanceBetween ### Description Calculates the geodesic distance between two latitude/longitude points on Earth using the Haversine formula. Supported unit strings are "meters", "kilometers", "miles", and "yards". ### Method ```dart static double distanceBetween(double lat1, double lon1, double lat2, double lon2, String unit) ``` ### Parameters #### Path Parameters - **lat1** (double) - Required - Latitude of the first point. - **lon1** (double) - Required - Longitude of the first point. - **lat2** (double) - Required - Latitude of the second point. - **lon2** (double) - Required - Longitude of the second point. - **unit** (String) - Required - The unit for the returned distance. Supported values: "meters", "kilometers", "miles", "yards". ### Request Example ```dart import 'package:flutter_map_math/flutter_geo_math.dart'; void main() { double distMeters = FlutterMapMath.distanceBetween( 37.4219999, -122.0840575, 37.4220011, -122.0866519, "meters", ); print('Distance: $distMeters meters'); double distMiles = FlutterMapMath.distanceBetween( 37.4219999, -122.0840575, 37.4220011, -122.0866519, "miles", ); print('Distance: $distMiles miles'); } ``` ### Response #### Success Response (200) - **distance** (double) - The calculated geodesic distance in the specified unit. ``` -------------------------------- ### DBSCAN Clustering Source: https://github.com/ujjwalsharma2210/flutter_map_math/blob/main/example/example.md Performs DBSCAN clustering on a list of points to identify dense regions. ```APIDOC ## dbscan ### Description Performs DBSCAN clustering on a list of points to identify dense regions. ### Method `FlutterCluster.dbscan(List points, double eps, int minPoints)` ### Parameters - **points** (List) - A list of geographical points to cluster. - **eps** (double) - The maximum distance (in meters) between two samples for one to be considered as in the neighborhood of the other. - **minPoints** (int) - The number of samples (or total weight) in a neighborhood for a point to be considered as a core point. This includes the point itself. ### Response Example ```dart final points = [ LatLng(37.7749, -122.4194), // San Francisco LatLng(37.7750, -122.4195), // Near San Francisco LatLng(37.8044, -122.2711), // Oakland LatLng(37.8045, -122.2712), // Near Oakland LatLng(37.6879, -122.4702), // Daly City ]; const double eps = 100; // 100 meters const int minPoints = 2; final clustersDBSCAN = FlutterCluster.dbscan(points, eps, minPoints); ``` ``` -------------------------------- ### midpointBetween Source: https://github.com/ujjwalsharma2210/flutter_map_math/blob/main/README.md Calculates the midpoint between two geographical points. ```APIDOC ## midpointBetween ### Description Calculates the midpoint between two geographical points. ### Method `FlutterMapMath.midpointBetween` ### Parameters - **point1** (LatLng) - The first geographical point. - **point2** (LatLng) - The second geographical point. ### Returns - **midpoint** (LatLng) - The geographical coordinates of the midpoint. ### Example ```dart LatLng location1 = LatLng(37.4219999, -122.0840575); LatLng location2 = LatLng(37.4220011, -122.0866519); LatLng midpoint = FlutterMapMath.midpointBetween(location1, location2); ``` ```