@umituz/react-native-location 1.0.0 → 1.0.3
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/package.json +3 -7
- package/src/domain/entities/Location.ts +16 -168
- package/src/index.ts +3 -107
- package/src/infrastructure/services/LocationService.ts +76 -286
- package/src/presentation/hooks/useLocation.ts +38 -221
- package/LICENSE +0 -22
- package/README.md +0 -127
- package/lib/domain/entities/Location.d.ts +0 -144
- package/lib/domain/entities/Location.d.ts.map +0 -1
- package/lib/domain/entities/Location.js +0 -52
- package/lib/domain/entities/Location.js.map +0 -1
- package/lib/index.d.ts +0 -95
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -95
- package/lib/index.js.map +0 -1
- package/lib/infrastructure/services/LocationService.d.ts +0 -93
- package/lib/infrastructure/services/LocationService.d.ts.map +0 -1
- package/lib/infrastructure/services/LocationService.js +0 -250
- package/lib/infrastructure/services/LocationService.js.map +0 -1
- package/lib/presentation/hooks/useLocation.d.ts +0 -95
- package/lib/presentation/hooks/useLocation.d.ts.map +0 -1
- package/lib/presentation/hooks/useLocation.js +0 -156
- package/lib/presentation/hooks/useLocation.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-location",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Device location services for React Native with GPS, permissions, caching, and reverse geocoding",
|
|
5
|
-
"main": "./
|
|
6
|
-
"types": "./
|
|
5
|
+
"main": "./src/index.ts",
|
|
6
|
+
"types": "./src/index.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"build": "tsc",
|
|
9
8
|
"typecheck": "tsc --noEmit",
|
|
10
9
|
"lint": "tsc --noEmit",
|
|
11
10
|
"clean": "rm -rf lib",
|
|
12
11
|
"prebuild": "npm run clean",
|
|
13
|
-
"prepublishOnly": "npm run build",
|
|
14
12
|
"version:patch": "npm version patch -m 'chore: release v%s'",
|
|
15
13
|
"version:minor": "npm version minor -m 'chore: release v%s'",
|
|
16
14
|
"version:major": "npm version major -m 'chore: release v%s'"
|
|
@@ -48,10 +46,8 @@
|
|
|
48
46
|
"access": "public"
|
|
49
47
|
},
|
|
50
48
|
"files": [
|
|
51
|
-
"lib",
|
|
52
49
|
"src",
|
|
53
50
|
"README.md",
|
|
54
51
|
"LICENSE"
|
|
55
52
|
]
|
|
56
53
|
}
|
|
57
|
-
|
|
@@ -1,175 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
/**
|
|
21
|
-
* Location data with coordinates and optional address
|
|
22
|
-
*/
|
|
23
|
-
export interface LocationData {
|
|
24
|
-
/** Latitude coordinate */
|
|
25
|
-
latitude: number;
|
|
26
|
-
|
|
27
|
-
/** Longitude coordinate */
|
|
28
|
-
longitude: number;
|
|
29
|
-
|
|
30
|
-
/** Human-readable address (reverse geocoded) */
|
|
31
|
-
address?: string;
|
|
32
|
-
|
|
33
|
-
/** Timestamp when location was captured (milliseconds since epoch) */
|
|
34
|
-
timestamp: number;
|
|
35
|
-
|
|
36
|
-
/** GPS accuracy in meters (lower is better) */
|
|
37
|
-
accuracy?: number;
|
|
38
|
-
|
|
39
|
-
/** Whether this location is from cache (not fresh GPS) */
|
|
40
|
-
isCached?: boolean;
|
|
1
|
+
export interface Coordinates {
|
|
2
|
+
latitude: number;
|
|
3
|
+
longitude: number;
|
|
41
4
|
}
|
|
42
5
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
* Location accuracy levels for GPS
|
|
50
|
-
*/
|
|
51
|
-
export enum LocationAccuracy {
|
|
52
|
-
/** Lowest accuracy, fastest response, battery-friendly */
|
|
53
|
-
Lowest = 1,
|
|
54
|
-
|
|
55
|
-
/** Low accuracy */
|
|
56
|
-
Low = 2,
|
|
57
|
-
|
|
58
|
-
/** Balanced accuracy (recommended for most use cases) */
|
|
59
|
-
Balanced = 3,
|
|
60
|
-
|
|
61
|
-
/** High accuracy (GPS-based) */
|
|
62
|
-
High = 4,
|
|
63
|
-
|
|
64
|
-
/** Highest accuracy (most battery-intensive) */
|
|
65
|
-
Highest = 5,
|
|
66
|
-
|
|
67
|
-
/** Best for navigation (continuous high accuracy) */
|
|
68
|
-
BestForNavigation = 6,
|
|
6
|
+
export interface LocationAddress {
|
|
7
|
+
city?: string | null;
|
|
8
|
+
region?: string | null;
|
|
9
|
+
country?: string | null;
|
|
10
|
+
street?: string | null;
|
|
11
|
+
formattedAddress?: string | null;
|
|
69
12
|
}
|
|
70
13
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
/** Cache duration in milliseconds (default: 15 minutes) */
|
|
76
|
-
duration: number;
|
|
77
|
-
|
|
78
|
-
/** Storage key for cached location */
|
|
79
|
-
storageKey: string;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Location retrieval configuration
|
|
84
|
-
*/
|
|
85
|
-
export interface LocationRetrievalConfig {
|
|
86
|
-
/** Timeout for high accuracy request (milliseconds) */
|
|
87
|
-
highAccuracyTimeout: number;
|
|
88
|
-
|
|
89
|
-
/** Timeout for balanced accuracy request (milliseconds) */
|
|
90
|
-
balancedAccuracyTimeout: number;
|
|
91
|
-
|
|
92
|
-
/** Whether to enable reverse geocoding (address lookup) */
|
|
93
|
-
enableGeocoding: boolean;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Cached location storage format
|
|
98
|
-
*/
|
|
99
|
-
export interface CachedLocation {
|
|
100
|
-
/** Location data */
|
|
101
|
-
data: LocationData;
|
|
102
|
-
|
|
103
|
-
/** Timestamp when location was cached (milliseconds since epoch) */
|
|
104
|
-
cachedAt: number;
|
|
14
|
+
export interface LocationData {
|
|
15
|
+
coords: Coordinates;
|
|
16
|
+
timestamp: number;
|
|
17
|
+
address?: LocationAddress;
|
|
105
18
|
}
|
|
106
19
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
*/
|
|
111
|
-
export interface ILocationService {
|
|
112
|
-
/**
|
|
113
|
-
* Request location permissions from user
|
|
114
|
-
* @returns Promise resolving to true if granted, false otherwise
|
|
115
|
-
*/
|
|
116
|
-
requestPermissions(): Promise<boolean>;
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Check if location permissions are granted
|
|
120
|
-
* @returns Promise resolving to true if granted, false otherwise
|
|
121
|
-
*/
|
|
122
|
-
hasPermissions(): Promise<boolean>;
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Get current permission status without requesting
|
|
126
|
-
* @returns Current permission status ('granted' | 'denied' | 'unknown')
|
|
127
|
-
*/
|
|
128
|
-
getPermissionStatus(): LocationPermissionStatus;
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Get current device location with fallback strategies
|
|
132
|
-
* Priority: High accuracy → Balanced accuracy → Cached location → null
|
|
133
|
-
* @returns Promise resolving to LocationData or null if unavailable
|
|
134
|
-
*/
|
|
135
|
-
getCurrentLocation(): Promise<LocationData | null>;
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Get cached location if available and not expired
|
|
139
|
-
* @returns Cached location or null
|
|
140
|
-
*/
|
|
141
|
-
getCachedLocation(): LocationData | null;
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Format location for display (address or coordinates)
|
|
145
|
-
* @param location - LocationData to format
|
|
146
|
-
* @returns Formatted string (address or "lat, lng")
|
|
147
|
-
*/
|
|
148
|
-
formatLocation(location: LocationData): string;
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Check if location services are available on this platform
|
|
152
|
-
* @returns True if available (iOS/Android), false otherwise (web)
|
|
153
|
-
*/
|
|
154
|
-
isLocationAvailable(): boolean;
|
|
20
|
+
export interface LocationError {
|
|
21
|
+
code: string;
|
|
22
|
+
message: string;
|
|
155
23
|
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Location service constants
|
|
159
|
-
*/
|
|
160
|
-
export const LOCATION_CONSTANTS = {
|
|
161
|
-
/** Cache duration: 15 minutes */
|
|
162
|
-
CACHE_DURATION: 15 * 60 * 1000,
|
|
163
|
-
|
|
164
|
-
/** High accuracy timeout: 15 seconds */
|
|
165
|
-
HIGH_ACCURACY_TIMEOUT: 15000,
|
|
166
|
-
|
|
167
|
-
/** Balanced accuracy timeout: 8 seconds */
|
|
168
|
-
BALANCED_ACCURACY_TIMEOUT: 8000,
|
|
169
|
-
|
|
170
|
-
/** AsyncStorage key for cached location */
|
|
171
|
-
CACHE_KEY: '@location_cache',
|
|
172
|
-
|
|
173
|
-
/** Coordinate decimal precision for display */
|
|
174
|
-
COORDINATE_PRECISION: 4,
|
|
175
|
-
} as const;
|
package/src/index.ts
CHANGED
|
@@ -1,107 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
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
|
-
|
|
91
|
-
// Domain Entities
|
|
92
|
-
export type {
|
|
93
|
-
LocationData,
|
|
94
|
-
LocationPermissionStatus,
|
|
95
|
-
CachedLocation,
|
|
96
|
-
LocationCacheConfig,
|
|
97
|
-
LocationRetrievalConfig,
|
|
98
|
-
ILocationService,
|
|
99
|
-
} from './domain/entities/Location';
|
|
100
|
-
export { LocationAccuracy, LOCATION_CONSTANTS } from './domain/entities/Location';
|
|
101
|
-
|
|
102
|
-
// Infrastructure Services
|
|
103
|
-
export { locationService } from './infrastructure/services/LocationService';
|
|
104
|
-
|
|
105
|
-
// Presentation Hooks
|
|
106
|
-
export { useLocation } from './presentation/hooks/useLocation';
|
|
107
|
-
export type { UseLocationReturn } from './presentation/hooks/useLocation';
|
|
1
|
+
export * from "./domain/entities/Location";
|
|
2
|
+
export * from "./infrastructure/services/LocationService";
|
|
3
|
+
export * from "./presentation/hooks/useLocation";
|