Skip to main content

Find Province from Coordinates

Find which Iranian province a set of GPS coordinates belongs to.

Basic Usage

import { findProvinceFromCoordinate } from "@persian-tools/persian-tools";

const province = findProvinceFromCoordinate({ latitude: 35.6892, longitude: 51.389 });
console.log(province);
// Output: "تهران"

API Reference

coordinates
object
required
result
string | undefined
Province name in Persian, or undefined if location is outside Iran

Examples

Location Services

import { findProvinceFromCoordinate } from "@persian-tools/persian-tools";

const getUserProvince = (coords: GeolocationCoordinates) => {
	const province = findProvinceFromCoordinate({
		latitude: coords.latitude,
		longitude: coords.longitude,
	});

	return province || "نامشخص";
};

Store Locator

import { findProvinceFromCoordinate } from "@persian-tools/persian-tools";

const findNearestStore = (userLat: number, userLng: number, stores: any[]) => {
	const userProvince = findProvinceFromCoordinate({
		latitude: userLat,
		longitude: userLng,
	});

	return stores.filter((store) => store.province === userProvince);
};

Type Definition

interface Coordinates {
	latitude: number;
	longitude: number;
}

function findProvinceFromCoordinate(coordinates: Coordinates): string | undefined;