A package for creating a triangle grid on a map. The grid is created by dividing the map into icosphere with 20 triangles and each triangle is divided into 4 smaller triangles and so on.
- Create triangle from location (latitude, longitude)
- Create location from triangle
- Get center of triangle
- Get triangles of specified depth in bounds
Install the package by adding the following to your pubspec.yaml
:
geo_triangle_grid: ^1.1.1
Import the package in your code:
import 'package:geo_triangle_grid/geo_triangle_grid.dart';
Here is a simple example of usage:
final location = LatLng(51.507351, -0.127758);
final triangleHash = TriangleGrid.latLngToHash(location);
print(triangleHash);
// prints: F203320022
final triangle = TriangleGrid.hashToLatLngTriangle(triangleHash);
print(triangle);
// prints: LatLng(latitude: 51.507351, longitude: -0.127758)
Converts a location to a triangle hash. The second parameter is optional and it is the length of the triangle grid. If not provided, the default value is 20.
String TriangleGrid.latLngToHash(LatLng location, [ int depth = 20 ]);
Converts a triangle hash to a triangle with points.
LatLngTriangle TriangleGrid.latLngToHash(String hash);
Converts a triangle hash to a location.
LatLng TriangleGrid.hashToLatLng(String hash);
Gets the center of the triangle.
LatLng get LatLngTriangle.center;
Package also provides some additional methods to work with vectors and triangles. All of them have documentation, you can find them in the API Reference.