flutter_map_math

Last updated:

0 purchases

flutter_map_math Image
flutter_map_math Images
Add to Cart

Description:

flutter map math

Map related Calculations Package for Flutter #
This package provides a set of utility classes and functions for performing map-related calculations in a Flutter application.
Installation #
To use this package, add map_calculation as a dependency in your 'pubspec.yaml' file:
dependencies:
flutter_map_math: ^1.0.0
copied to clipboard
Then, run 'flutter pub get' to install the package.
Usage #
Import the map_calculation package in your Dart code:
import 'package:flutter_map_math/flutter_map_math.dart';
copied to clipboard
Calculating Distance Between Two Points #
You can use the 'distanceBetween' function to calculate the distance between two points on a map. The function takes five arguments: the latitude and longitude of the first point, and the latitude and longitude of the second point and the units you want the distance in.
double distance = FlutterMapMath.distanceBetween(
37.4219999,
-122.0840575,
37.4220011,
-122.0866519,
"meters"
);
copied to clipboard
Available return units are : meters, kilometers, yards and miles. Replace the meters from above example to your required units.
Calculating Bearing Between Two Points #
You can use the 'bearingBetween' function to calculate the bearing between two points on a map. The function takes four arguments: the latitude and longitude of the first point, and the latitude and longitude of the second point.
The function returns the bearing in degrees.
double bearing = FlutterMapMath.bearingBetween(
37.4219999,
-122.0840575,
37.4220011,
-122.0866519,
);
copied to clipboard
Calculating Destination Point #
You can use the 'destinationPoint' function to calculate the destination point from a starting point, given a distance and a bearing. The function takes three arguments: the latitude and longitude of the starting point, the distance in meters, and the bearing in degrees.
The function returns a LatLng object representing the destination point.
LatLng startingPoint = LatLng(37.4219999, -122.0840575);
double distance = 1000;
double bearing = 90;
LatLng destinationPoint = FlutterMapMath.destinationPoint(startingPoint, distance, bearing);
copied to clipboard
Calculating Midpoint Between Two Points #
You can use the 'midpointBetween' function to calculate the midpoint between two points on a map. The function takes four arguments: the latitude and longitude of the first point, and the latitude and longitude of the second point.
The function returns a LatLng object representing the midpoint.
LatLng location1 = LatLng(37.4219999, -122.0840575);
LatLng location2 = LatLng(37.4220011, -122.0866519);
LatLng midpoint = FlutterMapMath.midpointBetween(point1, point2);
copied to clipboard
Calculating intersection point of two lines #
You can use the 'calculateIntersection' function to calculate the intersection of two lines on the map. The function takes six arguments: the latitude, longitude and bearing angle to first line, and the latitude, longitude and bearing angle of second line.
The function returns a LatLng object representing the intersection.
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);
copied to clipboard
Detecting proximity of points from one point #
You can use the 'detectProximity' function to check if any location in a list of locations has entered the proximity of a certain location. The function takes
three arguments: a LatLng object for the coordiantes of main location, List of LatLng objects and a double distance threashold.
The function returns a list of LatLng objects from the list which are in the proximity of the main location.
LatLng userLocation = LatLng(3.0, 5.0);
List<LatLng> 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<LatLng> nearbyPoints = FlutterMapMath.detectProximity(userLocation, mapPoints, distanceThreshold);

copied to clipboard
Creating virtual boundary around a point #
the 'createBoundary' function takes a 'LatLng' object representing the center of the boundary and a 'double' representing the radius of the
boundary in meters. It returns a function that takes a 'LatLng' object representing a location and returns a boolean indicating whether
the location is within the boundary.
You can use the 'createBoundary' function to create multiple boundaries and then use the returned functions to check whether a user or object is within each boundary.
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);
copied to clipboard
Calculating the area of a shape #
In this function, we first get the number of vertices of the shape and initialize the area to zero. We then loop over each pair of consecutive vertices, calculating the cross-product of the two vectors formed by the points. Finally, we divide the result by two to get the area of the shape.
Note that this function assumes that the vertices are ordered in a counterclockwise direction, and that the latitude and longitude values are stored in the 'latitude' and 'longitude' keys of each vertex dictionary, respectively. If the vertices are ordered clockwise, the calculated area will be negative, but we can simply take the absolute value to get the correct area.
List<Map<String, double>> rectangleVertices = [
{'latitude': 37.7749, 'longitude': -122.4194}, // San Francisco, CA
{'latitude': 37.7749, 'longitude': -122.4174},
{'latitude': 37.7769, 'longitude': -122.4174},
{'latitude': 37.7769, 'longitude': -122.4194},
];

double rectangleArea = calculateArea(rectangleVertices);

print('The area of the rectangle is $rectangleArea square degrees.');
copied to clipboard
TODOS #


Mapcoding: Applications may need to convert an address or place name into a latitude and longitude, or vice versa. This can be useful for finding the location of a place or for searching for nearby points of interest.


Routing: Applications may need to calculate the best route between two points on a map, taking into account factors such as traffic, road closures, and turn restrictions.


Area calculation: Applications may need to calculate the area of a shape, such as a polygon or circle. This can be useful for measuring the size of a parcel of land or for calculating the coverage area of a wireless network.


Elevation calculation: Applications may need to calculate the elevation of a point on a map, either as an absolute height above sea level or as a relative height above nearby terrain.


Heatmap generation: Applications may need to generate a heatmap of points or events on a map, which can be useful for visualizing patterns or clusters of activity.


Clustering: Applications may need to group nearby points on a map into clusters, which can be useful for reducing visual clutter or for identifying areas of high activity.


Tile generation: Applications may need to generate map tiles for use in custom map layers or overlays, which can be useful for adding custom data or visualizations to a map.


Point-of-interest identification: Applications may need to identify nearby points of interest, such as restaurants, gas stations, or landmarks. This can be useful for providing recommendations or directions to users.


Contributing #
We welcome contributions to this package. If you have an idea for a new feature or improvement, please open an issue on our GitHub repository. If you would like to contribute code, please fork the repository and submit a pull request. All contributions must adhere to our code of conduct.
License #
This package is released under the MIT license. See the LICENSE file for details.

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.