@inoxialabs/react-native-nitro-location-geocoder 0.1.0 → 1.0.1
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/NitroLocationGeocoder.podspec +28 -28
- package/README.md +120 -80
- package/android/CMakeLists.txt +25 -25
- package/android/build.gradle +129 -129
- package/android/fix-prefab.gradle +44 -44
- package/android/gradle.properties +5 -5
- package/android/src/main/AndroidManifest.xml +2 -2
- package/android/src/main/cpp/cpp-adapter.cpp +6 -6
- package/android/src/main/java/com/margelo/nitro/locationgeocoder/HybridLocationGeocoder.kt +123 -95
- package/android/src/main/java/com/margelo/nitro/locationgeocoder/NitroLocationGeocoderPackage.kt +18 -18
- package/ios/Bridge.h +1 -1
- package/ios/HybridLocationGeocoder.swift +92 -49
- package/nitro.json +24 -24
- package/nitrogen/generated/android/NitroLocationGeocoderOnLoad.cpp +2 -2
- package/nitrogen/generated/android/c++/JHybridLocationGeocoderSpec.hpp +2 -2
- package/nitrogen/generated/android/c++/JLocationGeocoderResult.hpp +2 -2
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/locationgeocoder/LocationGeocoderResult.kt +23 -0
- package/nitrogen/generated/ios/NitroLocationGeocoder+autolinking.rb +2 -0
- package/package.json +65 -65
- package/react-native.config.js +8 -8
- package/src/index.ts +53 -21
- package/src/specs/LocationGeocoder.nitro.ts +14 -14
package/package.json
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@inoxialabs/react-native-nitro-location-geocoder",
|
|
3
|
-
"version": "0.1
|
|
4
|
-
"description": "React Native Nitro module for reverse geocoding coordinates into country and locality context.",
|
|
5
|
-
"license": "Apache-2.0",
|
|
6
|
-
"author": "Inoxia Labs",
|
|
7
|
-
"main": "src/index",
|
|
8
|
-
"source": "src/index",
|
|
9
|
-
"types": "src/index.ts",
|
|
10
|
-
"react-native": "src/index",
|
|
11
|
-
"repository": {
|
|
12
|
-
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/inoxIALabs/react-native-nitro-location-geocoder.git"
|
|
14
|
-
},
|
|
15
|
-
"homepage": "https://github.com/inoxIALabs/react-native-nitro-location-geocoder#readme",
|
|
16
|
-
"bugs": {
|
|
17
|
-
"url": "https://github.com/inoxIALabs/react-native-nitro-location-geocoder/issues"
|
|
18
|
-
},
|
|
19
|
-
"publishConfig": {
|
|
20
|
-
"access": "public"
|
|
21
|
-
},
|
|
22
|
-
"keywords": [
|
|
23
|
-
"react-native",
|
|
24
|
-
"nitro",
|
|
25
|
-
"geocoder",
|
|
26
|
-
"location",
|
|
27
|
-
"country",
|
|
28
|
-
"locality",
|
|
29
|
-
"reverse-geocoding",
|
|
30
|
-
"ios",
|
|
31
|
-
"android"
|
|
32
|
-
],
|
|
33
|
-
"files": [
|
|
34
|
-
"src",
|
|
35
|
-
"react-native.config.js",
|
|
36
|
-
"nitro.json",
|
|
37
|
-
"nitrogen",
|
|
38
|
-
"android/build.gradle",
|
|
39
|
-
"android/fix-prefab.gradle",
|
|
40
|
-
"android/gradle.properties",
|
|
41
|
-
"android/CMakeLists.txt",
|
|
42
|
-
"android/src/**/*",
|
|
43
|
-
"ios/**/*.h",
|
|
44
|
-
"ios/**/*.m",
|
|
45
|
-
"ios/**/*.mm",
|
|
46
|
-
"ios/**/*.cpp",
|
|
47
|
-
"ios/**/*.swift",
|
|
48
|
-
"*.podspec",
|
|
49
|
-
"README.md",
|
|
50
|
-
"LICENSE"
|
|
51
|
-
],
|
|
52
|
-
"scripts": {
|
|
53
|
-
"specs": "nitrogen --logLevel=debug",
|
|
54
|
-
"test": "vitest run"
|
|
55
|
-
},
|
|
56
|
-
"peerDependencies": {
|
|
57
|
-
"react": "*",
|
|
58
|
-
"react-native": "*",
|
|
59
|
-
"react-native-nitro-modules": "^0.35.0"
|
|
60
|
-
},
|
|
61
|
-
"devDependencies": {
|
|
62
|
-
"nitrogen": "^0.
|
|
63
|
-
"vitest": "^3.2.4"
|
|
64
|
-
}
|
|
65
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@inoxialabs/react-native-nitro-location-geocoder",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "React Native Nitro module for reverse geocoding coordinates into country and locality context.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": "Inoxia Labs",
|
|
7
|
+
"main": "src/index",
|
|
8
|
+
"source": "src/index",
|
|
9
|
+
"types": "src/index.ts",
|
|
10
|
+
"react-native": "src/index",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/inoxIALabs/react-native-nitro-location-geocoder.git"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/inoxIALabs/react-native-nitro-location-geocoder#readme",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/inoxIALabs/react-native-nitro-location-geocoder/issues"
|
|
18
|
+
},
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"react-native",
|
|
24
|
+
"nitro",
|
|
25
|
+
"geocoder",
|
|
26
|
+
"location",
|
|
27
|
+
"country",
|
|
28
|
+
"locality",
|
|
29
|
+
"reverse-geocoding",
|
|
30
|
+
"ios",
|
|
31
|
+
"android"
|
|
32
|
+
],
|
|
33
|
+
"files": [
|
|
34
|
+
"src",
|
|
35
|
+
"react-native.config.js",
|
|
36
|
+
"nitro.json",
|
|
37
|
+
"nitrogen",
|
|
38
|
+
"android/build.gradle",
|
|
39
|
+
"android/fix-prefab.gradle",
|
|
40
|
+
"android/gradle.properties",
|
|
41
|
+
"android/CMakeLists.txt",
|
|
42
|
+
"android/src/**/*",
|
|
43
|
+
"ios/**/*.h",
|
|
44
|
+
"ios/**/*.m",
|
|
45
|
+
"ios/**/*.mm",
|
|
46
|
+
"ios/**/*.cpp",
|
|
47
|
+
"ios/**/*.swift",
|
|
48
|
+
"*.podspec",
|
|
49
|
+
"README.md",
|
|
50
|
+
"LICENSE"
|
|
51
|
+
],
|
|
52
|
+
"scripts": {
|
|
53
|
+
"specs": "nitrogen --logLevel=debug",
|
|
54
|
+
"test": "vitest run"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"react": "*",
|
|
58
|
+
"react-native": "*",
|
|
59
|
+
"react-native-nitro-modules": "^0.35.0 || ^0.36.0"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"nitrogen": "^0.36.1",
|
|
63
|
+
"vitest": "^3.2.4"
|
|
64
|
+
}
|
|
65
|
+
}
|
package/react-native.config.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
dependency: {
|
|
3
|
-
platforms: {
|
|
4
|
-
ios: {},
|
|
5
|
-
android: {},
|
|
6
|
-
},
|
|
7
|
-
},
|
|
8
|
-
};
|
|
1
|
+
module.exports = {
|
|
2
|
+
dependency: {
|
|
3
|
+
platforms: {
|
|
4
|
+
ios: {},
|
|
5
|
+
android: {},
|
|
6
|
+
},
|
|
7
|
+
},
|
|
8
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,21 +1,53 @@
|
|
|
1
|
-
import { NitroModules } from 'react-native-nitro-modules';
|
|
2
|
-
import type { LocationGeocoder, LocationGeocoderResult } from './specs/LocationGeocoder.nitro';
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
2
|
+
import type { LocationGeocoder, LocationGeocoderResult } from './specs/LocationGeocoder.nitro';
|
|
3
|
+
|
|
4
|
+
const KNOWN_ERROR_MESSAGES = [
|
|
5
|
+
'GEOCODER_FAILED',
|
|
6
|
+
'GEOCODER_TIMEOUT',
|
|
7
|
+
'INVALID_COORDINATES',
|
|
8
|
+
'NO_RESULTS',
|
|
9
|
+
'UNAVAILABLE',
|
|
10
|
+
] as const;
|
|
11
|
+
|
|
12
|
+
const createGeocoder = (): LocationGeocoder => {
|
|
13
|
+
return NitroModules.createHybridObject<LocationGeocoder>('LocationGeocoder');
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const Geocoder = createGeocoder();
|
|
17
|
+
|
|
18
|
+
const isValidLatitude = (latitude: number): boolean =>
|
|
19
|
+
Number.isFinite(latitude) && latitude >= -90 && latitude <= 90;
|
|
20
|
+
|
|
21
|
+
const isValidLongitude = (longitude: number): boolean =>
|
|
22
|
+
Number.isFinite(longitude) && longitude >= -180 && longitude <= 180;
|
|
23
|
+
|
|
24
|
+
const normalizeGeocoderError = (error: unknown): Error => {
|
|
25
|
+
const message = error instanceof Error
|
|
26
|
+
? error.message
|
|
27
|
+
: String((error as { message?: unknown } | null)?.message ?? error ?? '');
|
|
28
|
+
|
|
29
|
+
if (KNOWN_ERROR_MESSAGES.some((known) => message.startsWith(known))) {
|
|
30
|
+
return error instanceof Error ? error : new Error(message);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return new Error(`GEOCODER_FAILED${message ? `: ${message}` : ''}`);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const reverseGeocode = (
|
|
37
|
+
latitude: number,
|
|
38
|
+
longitude: number,
|
|
39
|
+
locale: string,
|
|
40
|
+
): Promise<LocationGeocoderResult> => {
|
|
41
|
+
if (!isValidLatitude(latitude) || !isValidLongitude(longitude)) {
|
|
42
|
+
return Promise.reject(new Error('INVALID_COORDINATES'));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return Geocoder.reverseGeocode(latitude, longitude, locale).catch((error: unknown) => {
|
|
46
|
+
throw normalizeGeocoderError(error);
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export { Geocoder };
|
|
51
|
+
export type { LocationGeocoder, LocationGeocoderResult };
|
|
52
|
+
|
|
53
|
+
export default Geocoder;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
-
|
|
3
|
-
export interface LocationGeocoderResult {
|
|
4
|
-
countryCode: string;
|
|
5
|
-
country: string;
|
|
6
|
-
locality: string;
|
|
7
|
-
administrativeArea: string;
|
|
8
|
-
subAdministrativeArea: string;
|
|
9
|
-
subLocality: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface LocationGeocoder extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
|
|
13
|
-
reverseGeocode(latitude: number, longitude: number, locale: string): Promise<LocationGeocoderResult>;
|
|
14
|
-
}
|
|
1
|
+
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
+
|
|
3
|
+
export interface LocationGeocoderResult {
|
|
4
|
+
countryCode: string;
|
|
5
|
+
country: string;
|
|
6
|
+
locality: string;
|
|
7
|
+
administrativeArea: string;
|
|
8
|
+
subAdministrativeArea: string;
|
|
9
|
+
subLocality: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface LocationGeocoder extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
|
|
13
|
+
reverseGeocode(latitude: number, longitude: number, locale: string): Promise<LocationGeocoderResult>;
|
|
14
|
+
}
|