Qibla direction, great-circle path, and haversine distance for Dart/Flutter. Pure math, zero dependencies.
Find a file
2026-03-08 15:44:02 -04:00
.github/workflows ci: run dart pub get before format check 2026-03-08 15:44:02 -04:00
lib Initial release: qibla v1.0.0 2026-03-08 12:58:43 -04:00
test Initial release: qibla v1.0.0 2026-03-08 12:58:43 -04:00
.gitignore Initial release: qibla v1.0.0 2026-03-08 12:58:43 -04:00
analysis_options.yaml Initial release: qibla v1.0.0 2026-03-08 12:58:43 -04:00
CHANGELOG.md Initial release: qibla v1.0.0 2026-03-08 12:58:43 -04:00
LICENSE Initial commit 2026-03-08 12:53:02 -04:00
pubspec.yaml Initial release: qibla v1.0.0 2026-03-08 12:58:43 -04:00
README.md Initial release: qibla v1.0.0 2026-03-08 12:58:43 -04:00

qibla

pub package CI License: MIT

Qibla direction, great-circle path, and haversine distance for Dart and Flutter. Pure math, zero dependencies.

Installation

dependencies:
  qibla: ^1.0.0

Quick Start

import 'package:qibla/qibla.dart';

// Bearing from New York to the Ka'bah
final bearing = qiblaAngle(40.7128, -74.006);
print(bearing);            // ~58.48
print(compassDir(bearing)); // NE

// Distance in kilometers
final km = distanceKm(40.7128, -74.006, kaabaLat, kaabaLng);
print(km); // ~9634

API

qiblaAngle(lat, lng)

Computes the initial bearing (forward azimuth) from the given coordinates to the Ka'bah.

Parameter Type Description
lat double Latitude in decimal degrees (-90 to 90)
lng double Longitude in decimal degrees (-180 to 180)
Returns double Bearing in degrees clockwise from north (0-360)

Throws RangeError if coordinates are out of bounds.

compassDir(bearing)

Eight-point compass abbreviation: N, NE, E, SE, S, SW, W, NW.

compassName(bearing)

Full compass name: North, Northeast, East, Southeast, South, Southwest, West, Northwest.

qiblaGreatCircle(lat, lng, [steps])

Generates waypoints along the great circle from (lat, lng) to the Ka'bah using spherical linear interpolation (Slerp). Returns steps + 1 points (default: 121).

Useful for drawing Qibla direction lines on maps.

distanceKm(lat1, lng1, lat2, lng2)

Haversine distance between two points in kilometers (spherical Earth approximation, R = 6,371 km).

Constants

Name Value Description
kaabaLat 21.422511 Ka'bah center latitude (degrees north)
kaabaLng 39.826150 Ka'bah center longitude (degrees east)
earthRadiusKm 6371 WGS-84 volumetric mean radius

Compatibility

Dart 3.7+. Works with Flutter and standalone Dart applications.

  • qibla (npm) - The TypeScript version of this package.
  • pray-calc - Islamic prayer times calculator.

License

MIT