expo-geofencing
Version:
Production-ready geofencing and activity recognition for Expo React Native with offline support, security features, and enterprise-grade reliability
101 lines (100 loc) • 3.16 kB
TypeScript
export interface Point {
latitude: number;
longitude: number;
}
export interface PolygonGeofenceRegion {
id: string;
name?: string;
vertices: Point[];
notifyOnEntry: boolean;
notifyOnExit: boolean;
metadata?: Record<string, any>;
}
export interface GeofenceHierarchy {
id: string;
parentId?: string;
children: string[];
inheritSettings: boolean;
overrides?: Partial<PolygonGeofenceRegion>;
}
export interface TimeBasedRule {
id: string;
startTime: string;
endTime: string;
daysOfWeek: number[];
timezone?: string;
isActive: boolean;
}
export interface ConditionalRule {
id: string;
condition: 'weather' | 'traffic' | 'activity' | 'custom';
operator: 'equals' | 'greater_than' | 'less_than' | 'contains';
value: any;
isActive: boolean;
}
export interface AdvancedGeofenceRegion extends PolygonGeofenceRegion {
type: 'circle' | 'polygon';
center?: Point;
radius?: number;
timeRules?: TimeBasedRule[];
conditionalRules?: ConditionalRule[];
hierarchy?: GeofenceHierarchy;
boundingBox?: {
minLat: number;
maxLat: number;
minLng: number;
maxLng: number;
};
}
export declare class PolygonGeofenceManager {
private geofences;
private spatialIndex;
private hierarchies;
private readonly GRID_SIZE;
addGeofence(region: Omit<AdvancedGeofenceRegion, 'boundingBox'>): string;
removeGeofence(regionId: string): boolean;
updateGeofence(regionId: string, updates: Partial<AdvancedGeofenceRegion>): boolean;
checkLocation(point: Point, timestamp?: number): {
entered: AdvancedGeofenceRegion[];
exited: AdvancedGeofenceRegion[];
inside: AdvancedGeofenceRegion[];
};
private isPointInside;
private isPointInCircle;
private isPointInPolygon;
private addToSpatialIndex;
private removeFromSpatialIndex;
private getCandidateGeofences;
private getGridCell;
private getGridCells;
private getAdjacentCells;
private calculateBoundingBox;
private isTimeRuleActive;
private isTimeInRange;
private timeToMinutes;
private areConditionalRulesActive;
private updateHierarchyReferences;
private removeFromHierarchy;
private calculateDistance;
private toRadians;
getGeofence(regionId: string): AdvancedGeofenceRegion | undefined;
getAllGeofences(): AdvancedGeofenceRegion[];
getGeofencesByType(type: 'circle' | 'polygon'): AdvancedGeofenceRegion[];
getActiveGeofences(timestamp?: number): AdvancedGeofenceRegion[];
getStatistics(): {
totalGeofences: number;
circularGeofences: number;
polygonGeofences: number;
timeBasedGeofences: number;
conditionalGeofences: number;
hierarchicalGeofences: number;
spatialIndexSize: number;
};
addMultipleGeofences(geofences: Omit<AdvancedGeofenceRegion, 'boundingBox'>[]): string[];
removeMultipleGeofences(regionIds: string[]): boolean[];
validatePolygon(vertices: Point[]): {
valid: boolean;
errors: string[];
};
private hasSimpleSelfIntersection;
}