@umituz/react-native-location 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +127 -0
- package/lib/domain/entities/Location.d.ts +144 -0
- package/lib/domain/entities/Location.d.ts.map +1 -0
- package/lib/domain/entities/Location.js +52 -0
- package/lib/domain/entities/Location.js.map +1 -0
- package/lib/index.d.ts +95 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +95 -0
- package/lib/index.js.map +1 -0
- package/lib/infrastructure/services/LocationService.d.ts +93 -0
- package/lib/infrastructure/services/LocationService.d.ts.map +1 -0
- package/lib/infrastructure/services/LocationService.js +250 -0
- package/lib/infrastructure/services/LocationService.js.map +1 -0
- package/lib/presentation/hooks/useLocation.d.ts +95 -0
- package/lib/presentation/hooks/useLocation.d.ts.map +1 -0
- package/lib/presentation/hooks/useLocation.js +156 -0
- package/lib/presentation/hooks/useLocation.js.map +1 -0
- package/package.json +57 -0
- package/src/domain/entities/Location.ts +175 -0
- package/src/index.ts +107 -0
- package/src/infrastructure/services/LocationService.ts +298 -0
- package/src/presentation/hooks/useLocation.ts +225 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Ümit UZ
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# @umituz/react-native-location
|
|
2
|
+
|
|
3
|
+
Device location services for React Native with GPS, permissions, caching, and reverse geocoding.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @umituz/react-native-location
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Peer Dependencies
|
|
12
|
+
|
|
13
|
+
- `react` >= 18.2.0
|
|
14
|
+
- `react-native` >= 0.74.0
|
|
15
|
+
- `expo-location` *
|
|
16
|
+
- `@react-native-async-storage/async-storage` *
|
|
17
|
+
|
|
18
|
+
## Features
|
|
19
|
+
|
|
20
|
+
- ✅ Current location retrieval with GPS
|
|
21
|
+
- ✅ Location permission management (iOS/Android)
|
|
22
|
+
- ✅ 15-minute location caching for performance
|
|
23
|
+
- ✅ Reverse geocoding (coordinates → address)
|
|
24
|
+
- ✅ Multi-tier accuracy fallback (High → Balanced → Cached)
|
|
25
|
+
- ✅ Platform-aware (iOS/Android only, no web support)
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### Using Hook (Recommended)
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { useLocation } from '@umituz/react-native-location';
|
|
33
|
+
|
|
34
|
+
const MyComponent = () => {
|
|
35
|
+
const {
|
|
36
|
+
location,
|
|
37
|
+
loading,
|
|
38
|
+
hasPermission,
|
|
39
|
+
requestPermission,
|
|
40
|
+
getCurrentLocation,
|
|
41
|
+
formatLocation,
|
|
42
|
+
} = useLocation();
|
|
43
|
+
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
// Auto-fetch on mount
|
|
46
|
+
getCurrentLocation();
|
|
47
|
+
}, []);
|
|
48
|
+
|
|
49
|
+
if (loading) return <LoadingIndicator />;
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<View>
|
|
53
|
+
{location && (
|
|
54
|
+
<>
|
|
55
|
+
<Text>Location: {formatLocation(location)}</Text>
|
|
56
|
+
<Text>Lat: {location.latitude}</Text>
|
|
57
|
+
<Text>Lng: {location.longitude}</Text>
|
|
58
|
+
{location.accuracy && (
|
|
59
|
+
<Text>Accuracy: {location.accuracy.toFixed(0)}m</Text>
|
|
60
|
+
)}
|
|
61
|
+
</>
|
|
62
|
+
)}
|
|
63
|
+
<Button onPress={getCurrentLocation}>
|
|
64
|
+
Refresh Location
|
|
65
|
+
</Button>
|
|
66
|
+
</View>
|
|
67
|
+
);
|
|
68
|
+
};
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Using Service Directly
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { locationService } from '@umituz/react-native-location';
|
|
75
|
+
|
|
76
|
+
// Check permission
|
|
77
|
+
const hasPermission = await locationService.hasPermissions();
|
|
78
|
+
|
|
79
|
+
// Request permission if needed
|
|
80
|
+
if (!hasPermission) {
|
|
81
|
+
const granted = await locationService.requestPermissions();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Get current location
|
|
85
|
+
const location = await locationService.getCurrentLocation();
|
|
86
|
+
if (location) {
|
|
87
|
+
console.log(locationService.formatLocation(location));
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Platform Support
|
|
92
|
+
|
|
93
|
+
- ✅ iOS: Full support (GPS, permissions, geocoding)
|
|
94
|
+
- ✅ Android: Full support (GPS, permissions, geocoding)
|
|
95
|
+
- ❌ Web: Not supported (returns null)
|
|
96
|
+
|
|
97
|
+
## Permission Flow
|
|
98
|
+
|
|
99
|
+
1. Check: `hasPermissions()` → true/false
|
|
100
|
+
2. Request: `requestPermissions()` → true/false
|
|
101
|
+
3. Retrieve: `getCurrentLocation()` → LocationData | null
|
|
102
|
+
|
|
103
|
+
## Fallback Strategy
|
|
104
|
+
|
|
105
|
+
1. High accuracy GPS (15s timeout)
|
|
106
|
+
2. Balanced accuracy GPS (8s timeout)
|
|
107
|
+
3. Cached location (15min cache)
|
|
108
|
+
4. null (no location available)
|
|
109
|
+
|
|
110
|
+
## Caching
|
|
111
|
+
|
|
112
|
+
- Duration: 15 minutes
|
|
113
|
+
- Storage: AsyncStorage
|
|
114
|
+
- Auto-refresh: On `getCurrentLocation()` if expired
|
|
115
|
+
|
|
116
|
+
## Hooks
|
|
117
|
+
|
|
118
|
+
- `useLocation()` - Main hook for location operations
|
|
119
|
+
|
|
120
|
+
## Services
|
|
121
|
+
|
|
122
|
+
- `locationService` - Direct service access for location operations
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
|
|
126
|
+
MIT
|
|
127
|
+
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Location Domain Entities
|
|
3
|
+
*
|
|
4
|
+
* Core location types and interfaces for device location services
|
|
5
|
+
* and geolocation features
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Current location retrieval with GPS
|
|
9
|
+
* - Location permission management
|
|
10
|
+
* - Location caching (15-minute cache)
|
|
11
|
+
* - Reverse geocoding (address lookup)
|
|
12
|
+
* - Fallback strategies (High → Balanced → Cached)
|
|
13
|
+
* - Platform-aware (iOS/Android only, no web)
|
|
14
|
+
*
|
|
15
|
+
* Dependencies:
|
|
16
|
+
* - expo-location (GPS and permissions)
|
|
17
|
+
* - AsyncStorage (location cache)
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Location data with coordinates and optional address
|
|
21
|
+
*/
|
|
22
|
+
export interface LocationData {
|
|
23
|
+
/** Latitude coordinate */
|
|
24
|
+
latitude: number;
|
|
25
|
+
/** Longitude coordinate */
|
|
26
|
+
longitude: number;
|
|
27
|
+
/** Human-readable address (reverse geocoded) */
|
|
28
|
+
address?: string;
|
|
29
|
+
/** Timestamp when location was captured (milliseconds since epoch) */
|
|
30
|
+
timestamp: number;
|
|
31
|
+
/** GPS accuracy in meters (lower is better) */
|
|
32
|
+
accuracy?: number;
|
|
33
|
+
/** Whether this location is from cache (not fresh GPS) */
|
|
34
|
+
isCached?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Location permission status
|
|
38
|
+
*/
|
|
39
|
+
export type LocationPermissionStatus = 'granted' | 'denied' | 'unknown';
|
|
40
|
+
/**
|
|
41
|
+
* Location accuracy levels for GPS
|
|
42
|
+
*/
|
|
43
|
+
export declare enum LocationAccuracy {
|
|
44
|
+
/** Lowest accuracy, fastest response, battery-friendly */
|
|
45
|
+
Lowest = 1,
|
|
46
|
+
/** Low accuracy */
|
|
47
|
+
Low = 2,
|
|
48
|
+
/** Balanced accuracy (recommended for most use cases) */
|
|
49
|
+
Balanced = 3,
|
|
50
|
+
/** High accuracy (GPS-based) */
|
|
51
|
+
High = 4,
|
|
52
|
+
/** Highest accuracy (most battery-intensive) */
|
|
53
|
+
Highest = 5,
|
|
54
|
+
/** Best for navigation (continuous high accuracy) */
|
|
55
|
+
BestForNavigation = 6
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Location cache configuration
|
|
59
|
+
*/
|
|
60
|
+
export interface LocationCacheConfig {
|
|
61
|
+
/** Cache duration in milliseconds (default: 15 minutes) */
|
|
62
|
+
duration: number;
|
|
63
|
+
/** Storage key for cached location */
|
|
64
|
+
storageKey: string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Location retrieval configuration
|
|
68
|
+
*/
|
|
69
|
+
export interface LocationRetrievalConfig {
|
|
70
|
+
/** Timeout for high accuracy request (milliseconds) */
|
|
71
|
+
highAccuracyTimeout: number;
|
|
72
|
+
/** Timeout for balanced accuracy request (milliseconds) */
|
|
73
|
+
balancedAccuracyTimeout: number;
|
|
74
|
+
/** Whether to enable reverse geocoding (address lookup) */
|
|
75
|
+
enableGeocoding: boolean;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Cached location storage format
|
|
79
|
+
*/
|
|
80
|
+
export interface CachedLocation {
|
|
81
|
+
/** Location data */
|
|
82
|
+
data: LocationData;
|
|
83
|
+
/** Timestamp when location was cached (milliseconds since epoch) */
|
|
84
|
+
cachedAt: number;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Location Service Interface
|
|
88
|
+
* Defines all location-related operations
|
|
89
|
+
*/
|
|
90
|
+
export interface ILocationService {
|
|
91
|
+
/**
|
|
92
|
+
* Request location permissions from user
|
|
93
|
+
* @returns Promise resolving to true if granted, false otherwise
|
|
94
|
+
*/
|
|
95
|
+
requestPermissions(): Promise<boolean>;
|
|
96
|
+
/**
|
|
97
|
+
* Check if location permissions are granted
|
|
98
|
+
* @returns Promise resolving to true if granted, false otherwise
|
|
99
|
+
*/
|
|
100
|
+
hasPermissions(): Promise<boolean>;
|
|
101
|
+
/**
|
|
102
|
+
* Get current permission status without requesting
|
|
103
|
+
* @returns Current permission status ('granted' | 'denied' | 'unknown')
|
|
104
|
+
*/
|
|
105
|
+
getPermissionStatus(): LocationPermissionStatus;
|
|
106
|
+
/**
|
|
107
|
+
* Get current device location with fallback strategies
|
|
108
|
+
* Priority: High accuracy → Balanced accuracy → Cached location → null
|
|
109
|
+
* @returns Promise resolving to LocationData or null if unavailable
|
|
110
|
+
*/
|
|
111
|
+
getCurrentLocation(): Promise<LocationData | null>;
|
|
112
|
+
/**
|
|
113
|
+
* Get cached location if available and not expired
|
|
114
|
+
* @returns Cached location or null
|
|
115
|
+
*/
|
|
116
|
+
getCachedLocation(): LocationData | null;
|
|
117
|
+
/**
|
|
118
|
+
* Format location for display (address or coordinates)
|
|
119
|
+
* @param location - LocationData to format
|
|
120
|
+
* @returns Formatted string (address or "lat, lng")
|
|
121
|
+
*/
|
|
122
|
+
formatLocation(location: LocationData): string;
|
|
123
|
+
/**
|
|
124
|
+
* Check if location services are available on this platform
|
|
125
|
+
* @returns True if available (iOS/Android), false otherwise (web)
|
|
126
|
+
*/
|
|
127
|
+
isLocationAvailable(): boolean;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Location service constants
|
|
131
|
+
*/
|
|
132
|
+
export declare const LOCATION_CONSTANTS: {
|
|
133
|
+
/** Cache duration: 15 minutes */
|
|
134
|
+
readonly CACHE_DURATION: number;
|
|
135
|
+
/** High accuracy timeout: 15 seconds */
|
|
136
|
+
readonly HIGH_ACCURACY_TIMEOUT: 15000;
|
|
137
|
+
/** Balanced accuracy timeout: 8 seconds */
|
|
138
|
+
readonly BALANCED_ACCURACY_TIMEOUT: 8000;
|
|
139
|
+
/** AsyncStorage key for cached location */
|
|
140
|
+
readonly CACHE_KEY: "@location_cache";
|
|
141
|
+
/** Coordinate decimal precision for display */
|
|
142
|
+
readonly COORDINATE_PRECISION: 4;
|
|
143
|
+
};
|
|
144
|
+
//# sourceMappingURL=Location.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Location.d.ts","sourceRoot":"","sources":["../../../src/domain/entities/Location.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,0BAA0B;IAC1B,QAAQ,EAAE,MAAM,CAAC;IAEjB,2BAA2B;IAC3B,SAAS,EAAE,MAAM,CAAC;IAElB,gDAAgD;IAChD,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,sEAAsE;IACtE,SAAS,EAAE,MAAM,CAAC;IAElB,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;AAExE;;GAEG;AACH,oBAAY,gBAAgB;IAC1B,0DAA0D;IAC1D,MAAM,IAAI;IAEV,mBAAmB;IACnB,GAAG,IAAI;IAEP,yDAAyD;IACzD,QAAQ,IAAI;IAEZ,gCAAgC;IAChC,IAAI,IAAI;IAER,gDAAgD;IAChD,OAAO,IAAI;IAEX,qDAAqD;IACrD,iBAAiB,IAAI;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,CAAC;IAEjB,sCAAsC;IACtC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,uDAAuD;IACvD,mBAAmB,EAAE,MAAM,CAAC;IAE5B,2DAA2D;IAC3D,uBAAuB,EAAE,MAAM,CAAC;IAEhC,2DAA2D;IAC3D,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,oBAAoB;IACpB,IAAI,EAAE,YAAY,CAAC;IAEnB,oEAAoE;IACpE,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,kBAAkB,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAEvC;;;OAGG;IACH,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAEnC;;;OAGG;IACH,mBAAmB,IAAI,wBAAwB,CAAC;IAEhD;;;;OAIG;IACH,kBAAkB,IAAI,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IAEnD;;;OAGG;IACH,iBAAiB,IAAI,YAAY,GAAG,IAAI,CAAC;IAEzC;;;;OAIG;IACH,cAAc,CAAC,QAAQ,EAAE,YAAY,GAAG,MAAM,CAAC;IAE/C;;;OAGG;IACH,mBAAmB,IAAI,OAAO,CAAC;CAChC;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB;IAC7B,iCAAiC;;IAGjC,wCAAwC;;IAGxC,2CAA2C;;IAG3C,2CAA2C;;IAG3C,+CAA+C;;CAEvC,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Location Domain Entities
|
|
3
|
+
*
|
|
4
|
+
* Core location types and interfaces for device location services
|
|
5
|
+
* and geolocation features
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Current location retrieval with GPS
|
|
9
|
+
* - Location permission management
|
|
10
|
+
* - Location caching (15-minute cache)
|
|
11
|
+
* - Reverse geocoding (address lookup)
|
|
12
|
+
* - Fallback strategies (High → Balanced → Cached)
|
|
13
|
+
* - Platform-aware (iOS/Android only, no web)
|
|
14
|
+
*
|
|
15
|
+
* Dependencies:
|
|
16
|
+
* - expo-location (GPS and permissions)
|
|
17
|
+
* - AsyncStorage (location cache)
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Location accuracy levels for GPS
|
|
21
|
+
*/
|
|
22
|
+
export var LocationAccuracy;
|
|
23
|
+
(function (LocationAccuracy) {
|
|
24
|
+
/** Lowest accuracy, fastest response, battery-friendly */
|
|
25
|
+
LocationAccuracy[LocationAccuracy["Lowest"] = 1] = "Lowest";
|
|
26
|
+
/** Low accuracy */
|
|
27
|
+
LocationAccuracy[LocationAccuracy["Low"] = 2] = "Low";
|
|
28
|
+
/** Balanced accuracy (recommended for most use cases) */
|
|
29
|
+
LocationAccuracy[LocationAccuracy["Balanced"] = 3] = "Balanced";
|
|
30
|
+
/** High accuracy (GPS-based) */
|
|
31
|
+
LocationAccuracy[LocationAccuracy["High"] = 4] = "High";
|
|
32
|
+
/** Highest accuracy (most battery-intensive) */
|
|
33
|
+
LocationAccuracy[LocationAccuracy["Highest"] = 5] = "Highest";
|
|
34
|
+
/** Best for navigation (continuous high accuracy) */
|
|
35
|
+
LocationAccuracy[LocationAccuracy["BestForNavigation"] = 6] = "BestForNavigation";
|
|
36
|
+
})(LocationAccuracy || (LocationAccuracy = {}));
|
|
37
|
+
/**
|
|
38
|
+
* Location service constants
|
|
39
|
+
*/
|
|
40
|
+
export const LOCATION_CONSTANTS = {
|
|
41
|
+
/** Cache duration: 15 minutes */
|
|
42
|
+
CACHE_DURATION: 15 * 60 * 1000,
|
|
43
|
+
/** High accuracy timeout: 15 seconds */
|
|
44
|
+
HIGH_ACCURACY_TIMEOUT: 15000,
|
|
45
|
+
/** Balanced accuracy timeout: 8 seconds */
|
|
46
|
+
BALANCED_ACCURACY_TIMEOUT: 8000,
|
|
47
|
+
/** AsyncStorage key for cached location */
|
|
48
|
+
CACHE_KEY: '@location_cache',
|
|
49
|
+
/** Coordinate decimal precision for display */
|
|
50
|
+
COORDINATE_PRECISION: 4,
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=Location.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Location.js","sourceRoot":"","sources":["../../../src/domain/entities/Location.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AA8BH;;GAEG;AACH,MAAM,CAAN,IAAY,gBAkBX;AAlBD,WAAY,gBAAgB;IAC1B,0DAA0D;IAC1D,2DAAU,CAAA;IAEV,mBAAmB;IACnB,qDAAO,CAAA;IAEP,yDAAyD;IACzD,+DAAY,CAAA;IAEZ,gCAAgC;IAChC,uDAAQ,CAAA;IAER,gDAAgD;IAChD,6DAAW,CAAA;IAEX,qDAAqD;IACrD,iFAAqB,CAAA;AACvB,CAAC,EAlBW,gBAAgB,KAAhB,gBAAgB,QAkB3B;AAwFD;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,iCAAiC;IACjC,cAAc,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI;IAE9B,wCAAwC;IACxC,qBAAqB,EAAE,KAAK;IAE5B,2CAA2C;IAC3C,yBAAyB,EAAE,IAAI;IAE/B,2CAA2C;IAC3C,SAAS,EAAE,iBAAiB;IAE5B,+CAA+C;IAC/C,oBAAoB,EAAE,CAAC;CACf,CAAC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Location Domain - Barrel Export
|
|
3
|
+
*
|
|
4
|
+
* Global infrastructure domain for device location services and geolocation
|
|
5
|
+
*
|
|
6
|
+
* Features:
|
|
7
|
+
* - Current location retrieval with GPS
|
|
8
|
+
* - Location permission management (iOS/Android)
|
|
9
|
+
* - 15-minute location caching for performance
|
|
10
|
+
* - Reverse geocoding (coordinates → address)
|
|
11
|
+
* - Multi-tier accuracy fallback (High → Balanced → Cached)
|
|
12
|
+
* - Platform-aware (iOS/Android only, no web support)
|
|
13
|
+
* - Silent failures (no console logging)
|
|
14
|
+
*
|
|
15
|
+
* Dependencies:
|
|
16
|
+
* - expo-location (GPS and permissions API)
|
|
17
|
+
* - AsyncStorage (cache persistence)
|
|
18
|
+
*
|
|
19
|
+
* USAGE:
|
|
20
|
+
* ```typescript
|
|
21
|
+
* // Recommended: Use hook in components
|
|
22
|
+
* import { useLocation } from '@umituz/react-native-location';
|
|
23
|
+
*
|
|
24
|
+
* const MyComponent = () => {
|
|
25
|
+
* const {
|
|
26
|
+
* location,
|
|
27
|
+
* loading,
|
|
28
|
+
* hasPermission,
|
|
29
|
+
* requestPermission,
|
|
30
|
+
* getCurrentLocation,
|
|
31
|
+
* formatLocation,
|
|
32
|
+
* } = useLocation();
|
|
33
|
+
*
|
|
34
|
+
* useEffect(() => {
|
|
35
|
+
* // Auto-fetch on mount
|
|
36
|
+
* getCurrentLocation();
|
|
37
|
+
* }, []);
|
|
38
|
+
*
|
|
39
|
+
* if (loading) return <LoadingIndicator />;
|
|
40
|
+
*
|
|
41
|
+
* return (
|
|
42
|
+
* <View>
|
|
43
|
+
* {location && (
|
|
44
|
+
* <>
|
|
45
|
+
* <Text>Location: {formatLocation(location)}</Text>
|
|
46
|
+
* <Text>Lat: {location.latitude}</Text>
|
|
47
|
+
* <Text>Lng: {location.longitude}</Text>
|
|
48
|
+
* {location.accuracy && (
|
|
49
|
+
* <Text>Accuracy: {location.accuracy.toFixed(0)}m</Text>
|
|
50
|
+
* )}
|
|
51
|
+
* </>
|
|
52
|
+
* )}
|
|
53
|
+
* <AtomicButton onPress={getCurrentLocation}>
|
|
54
|
+
* Refresh Location
|
|
55
|
+
* </AtomicButton>
|
|
56
|
+
* </View>
|
|
57
|
+
* );
|
|
58
|
+
* };
|
|
59
|
+
*
|
|
60
|
+
* // Alternative: Use service directly (for non-component code)
|
|
61
|
+
* import { locationService } from '@umituz/react-native-location';
|
|
62
|
+
*
|
|
63
|
+
* const location = await locationService.getCurrentLocation();
|
|
64
|
+
* if (location) {
|
|
65
|
+
* console.log(locationService.formatLocation(location));
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* PLATFORM SUPPORT:
|
|
70
|
+
* - ✅ iOS: Full support (GPS, permissions, geocoding)
|
|
71
|
+
* - ✅ Android: Full support (GPS, permissions, geocoding)
|
|
72
|
+
* - ❌ Web: Not supported (returns null)
|
|
73
|
+
*
|
|
74
|
+
* PERMISSION FLOW:
|
|
75
|
+
* 1. Check: hasPermissions() → true/false
|
|
76
|
+
* 2. Request: requestPermissions() → true/false
|
|
77
|
+
* 3. Retrieve: getCurrentLocation() → LocationData | null
|
|
78
|
+
*
|
|
79
|
+
* FALLBACK STRATEGY:
|
|
80
|
+
* 1. High accuracy GPS (15s timeout)
|
|
81
|
+
* 2. Balanced accuracy GPS (8s timeout)
|
|
82
|
+
* 3. Cached location (15min cache)
|
|
83
|
+
* 4. null (no location available)
|
|
84
|
+
*
|
|
85
|
+
* CACHING:
|
|
86
|
+
* - Duration: 15 minutes
|
|
87
|
+
* - Storage: AsyncStorage (@location_cache)
|
|
88
|
+
* - Auto-refresh: On getCurrentLocation() if expired
|
|
89
|
+
*/
|
|
90
|
+
export type { LocationData, LocationPermissionStatus, CachedLocation, LocationCacheConfig, LocationRetrievalConfig, ILocationService, } from './domain/entities/Location';
|
|
91
|
+
export { LocationAccuracy, LOCATION_CONSTANTS } from './domain/entities/Location';
|
|
92
|
+
export { locationService } from './infrastructure/services/LocationService';
|
|
93
|
+
export { useLocation } from './presentation/hooks/useLocation';
|
|
94
|
+
export type { UseLocationReturn } from './presentation/hooks/useLocation';
|
|
95
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwFG;AAGH,YAAY,EACV,YAAY,EACZ,wBAAwB,EACxB,cAAc,EACd,mBAAmB,EACnB,uBAAuB,EACvB,gBAAgB,GACjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAGlF,OAAO,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AAG5E,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAC/D,YAAY,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Location Domain - Barrel Export
|
|
3
|
+
*
|
|
4
|
+
* Global infrastructure domain for device location services and geolocation
|
|
5
|
+
*
|
|
6
|
+
* Features:
|
|
7
|
+
* - Current location retrieval with GPS
|
|
8
|
+
* - Location permission management (iOS/Android)
|
|
9
|
+
* - 15-minute location caching for performance
|
|
10
|
+
* - Reverse geocoding (coordinates → address)
|
|
11
|
+
* - Multi-tier accuracy fallback (High → Balanced → Cached)
|
|
12
|
+
* - Platform-aware (iOS/Android only, no web support)
|
|
13
|
+
* - Silent failures (no console logging)
|
|
14
|
+
*
|
|
15
|
+
* Dependencies:
|
|
16
|
+
* - expo-location (GPS and permissions API)
|
|
17
|
+
* - AsyncStorage (cache persistence)
|
|
18
|
+
*
|
|
19
|
+
* USAGE:
|
|
20
|
+
* ```typescript
|
|
21
|
+
* // Recommended: Use hook in components
|
|
22
|
+
* import { useLocation } from '@umituz/react-native-location';
|
|
23
|
+
*
|
|
24
|
+
* const MyComponent = () => {
|
|
25
|
+
* const {
|
|
26
|
+
* location,
|
|
27
|
+
* loading,
|
|
28
|
+
* hasPermission,
|
|
29
|
+
* requestPermission,
|
|
30
|
+
* getCurrentLocation,
|
|
31
|
+
* formatLocation,
|
|
32
|
+
* } = useLocation();
|
|
33
|
+
*
|
|
34
|
+
* useEffect(() => {
|
|
35
|
+
* // Auto-fetch on mount
|
|
36
|
+
* getCurrentLocation();
|
|
37
|
+
* }, []);
|
|
38
|
+
*
|
|
39
|
+
* if (loading) return <LoadingIndicator />;
|
|
40
|
+
*
|
|
41
|
+
* return (
|
|
42
|
+
* <View>
|
|
43
|
+
* {location && (
|
|
44
|
+
* <>
|
|
45
|
+
* <Text>Location: {formatLocation(location)}</Text>
|
|
46
|
+
* <Text>Lat: {location.latitude}</Text>
|
|
47
|
+
* <Text>Lng: {location.longitude}</Text>
|
|
48
|
+
* {location.accuracy && (
|
|
49
|
+
* <Text>Accuracy: {location.accuracy.toFixed(0)}m</Text>
|
|
50
|
+
* )}
|
|
51
|
+
* </>
|
|
52
|
+
* )}
|
|
53
|
+
* <AtomicButton onPress={getCurrentLocation}>
|
|
54
|
+
* Refresh Location
|
|
55
|
+
* </AtomicButton>
|
|
56
|
+
* </View>
|
|
57
|
+
* );
|
|
58
|
+
* };
|
|
59
|
+
*
|
|
60
|
+
* // Alternative: Use service directly (for non-component code)
|
|
61
|
+
* import { locationService } from '@umituz/react-native-location';
|
|
62
|
+
*
|
|
63
|
+
* const location = await locationService.getCurrentLocation();
|
|
64
|
+
* if (location) {
|
|
65
|
+
* console.log(locationService.formatLocation(location));
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* PLATFORM SUPPORT:
|
|
70
|
+
* - ✅ iOS: Full support (GPS, permissions, geocoding)
|
|
71
|
+
* - ✅ Android: Full support (GPS, permissions, geocoding)
|
|
72
|
+
* - ❌ Web: Not supported (returns null)
|
|
73
|
+
*
|
|
74
|
+
* PERMISSION FLOW:
|
|
75
|
+
* 1. Check: hasPermissions() → true/false
|
|
76
|
+
* 2. Request: requestPermissions() → true/false
|
|
77
|
+
* 3. Retrieve: getCurrentLocation() → LocationData | null
|
|
78
|
+
*
|
|
79
|
+
* FALLBACK STRATEGY:
|
|
80
|
+
* 1. High accuracy GPS (15s timeout)
|
|
81
|
+
* 2. Balanced accuracy GPS (8s timeout)
|
|
82
|
+
* 3. Cached location (15min cache)
|
|
83
|
+
* 4. null (no location available)
|
|
84
|
+
*
|
|
85
|
+
* CACHING:
|
|
86
|
+
* - Duration: 15 minutes
|
|
87
|
+
* - Storage: AsyncStorage (@location_cache)
|
|
88
|
+
* - Auto-refresh: On getCurrentLocation() if expired
|
|
89
|
+
*/
|
|
90
|
+
export { LocationAccuracy, LOCATION_CONSTANTS } from './domain/entities/Location';
|
|
91
|
+
// Infrastructure Services
|
|
92
|
+
export { locationService } from './infrastructure/services/LocationService';
|
|
93
|
+
// Presentation Hooks
|
|
94
|
+
export { useLocation } from './presentation/hooks/useLocation';
|
|
95
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwFG;AAWH,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAElF,0BAA0B;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AAE5E,qBAAqB;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Location Service Implementation
|
|
3
|
+
*
|
|
4
|
+
* Handles device location retrieval, permissions, caching, and reverse geocoding
|
|
5
|
+
* with intelligent fallback strategies
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Multi-tier accuracy fallback (High → Balanced → Cached)
|
|
9
|
+
* - 15-minute location caching for performance
|
|
10
|
+
* - Reverse geocoding with coordinate fallback
|
|
11
|
+
* - Platform detection (iOS/Android only, no web)
|
|
12
|
+
* - Silent failures (no console logging)
|
|
13
|
+
* - AsyncStorage persistence
|
|
14
|
+
*
|
|
15
|
+
* Dependencies:
|
|
16
|
+
* - expo-location (GPS and permissions API)
|
|
17
|
+
* - AsyncStorage (cache persistence)
|
|
18
|
+
*
|
|
19
|
+
* USAGE:
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { locationService } from '@umituz/react-native-location';
|
|
22
|
+
*
|
|
23
|
+
* // Check permission
|
|
24
|
+
* const hasPermission = await locationService.hasPermissions();
|
|
25
|
+
*
|
|
26
|
+
* // Request permission if needed
|
|
27
|
+
* if (!hasPermission) {
|
|
28
|
+
* const granted = await locationService.requestPermissions();
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* // Get current location
|
|
32
|
+
* const location = await locationService.getCurrentLocation();
|
|
33
|
+
* if (location) {
|
|
34
|
+
* console.log(location.latitude, location.longitude);
|
|
35
|
+
* console.log(locationService.formatLocation(location));
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
import type { LocationData, LocationPermissionStatus, ILocationService } from '../../domain/entities/Location';
|
|
40
|
+
declare class LocationService implements ILocationService {
|
|
41
|
+
private cachedLocation;
|
|
42
|
+
private cachedAt;
|
|
43
|
+
private permissionStatus;
|
|
44
|
+
constructor();
|
|
45
|
+
/**
|
|
46
|
+
* Check if location services are available on this platform
|
|
47
|
+
*/
|
|
48
|
+
isLocationAvailable(): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Load cached location from AsyncStorage
|
|
51
|
+
*/
|
|
52
|
+
private loadCachedLocation;
|
|
53
|
+
/**
|
|
54
|
+
* Save location to cache (AsyncStorage + memory)
|
|
55
|
+
*/
|
|
56
|
+
private saveCachedLocation;
|
|
57
|
+
/**
|
|
58
|
+
* Get cached location if available and not expired
|
|
59
|
+
*/
|
|
60
|
+
getCachedLocation(): LocationData | null;
|
|
61
|
+
/**
|
|
62
|
+
* Request location permissions from user
|
|
63
|
+
*/
|
|
64
|
+
requestPermissions(): Promise<boolean>;
|
|
65
|
+
/**
|
|
66
|
+
* Check if location permissions are granted
|
|
67
|
+
*/
|
|
68
|
+
hasPermissions(): Promise<boolean>;
|
|
69
|
+
/**
|
|
70
|
+
* Get permission status without requesting
|
|
71
|
+
*/
|
|
72
|
+
getPermissionStatus(): LocationPermissionStatus;
|
|
73
|
+
/**
|
|
74
|
+
* Get current location with fallback strategies
|
|
75
|
+
* Priority: High accuracy → Balanced accuracy → Cached location → null
|
|
76
|
+
*/
|
|
77
|
+
getCurrentLocation(): Promise<LocationData | null>;
|
|
78
|
+
/**
|
|
79
|
+
* Get location with specific accuracy and timeout
|
|
80
|
+
*/
|
|
81
|
+
private getLocationWithAccuracy;
|
|
82
|
+
/**
|
|
83
|
+
* Format location for display (address or coordinates)
|
|
84
|
+
*/
|
|
85
|
+
formatLocation(location: LocationData): string;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Singleton instance
|
|
89
|
+
* Use this for all location operations
|
|
90
|
+
*/
|
|
91
|
+
export declare const locationService: LocationService;
|
|
92
|
+
export {};
|
|
93
|
+
//# sourceMappingURL=LocationService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocationService.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/services/LocationService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAMH,OAAO,KAAK,EACV,YAAY,EACZ,wBAAwB,EAExB,gBAAgB,EACjB,MAAM,gCAAgC,CAAC;AAGxC,cAAM,eAAgB,YAAW,gBAAgB;IAC/C,OAAO,CAAC,cAAc,CAA6B;IACnD,OAAO,CAAC,QAAQ,CAAa;IAC7B,OAAO,CAAC,gBAAgB,CAAuC;;IAM/D;;OAEG;IACH,mBAAmB,IAAI,OAAO;IAQ9B;;OAEG;YACW,kBAAkB;IAkBhC;;OAEG;YACW,kBAAkB;IAiBhC;;OAEG;IACH,iBAAiB,IAAI,YAAY,GAAG,IAAI;IAWxC;;OAEG;IACG,kBAAkB,IAAI,OAAO,CAAC,OAAO,CAAC;IAgB5C;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC;IAoBxC;;OAEG;IACH,mBAAmB,IAAI,wBAAwB;IAI/C;;;OAGG;IACG,kBAAkB,IAAI,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IA6CxD;;OAEG;YACW,uBAAuB;IAqDrC;;OAEG;IACH,cAAc,CAAC,QAAQ,EAAE,YAAY,GAAG,MAAM;CAQ/C;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,iBAAwB,CAAC"}
|