toTileIndex method

  1. @override
TileIndex toTileIndex(
  1. LatLng location
)
override

Converts a LatLng to its corresponing TileIndex screen coordinates.

Implementation

@override
TileIndex toTileIndex(LatLng location) {
  final lng = location.longitude.degrees;
  final lat = location.latitude.degrees;

  double x = (lng + 180.0) / 360.0;
  double sinLatitude = sin(lat * pi / 180.0);
  double y =
      0.5 - log((1.0 + sinLatitude) / (1.0 - sinLatitude)) / (4.0 * pi);

  return TileIndex(x, y);
}