react-native-nitro-location-tracking 0.1.11 → 0.1.13
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/README.md +30 -8
- package/android/CMakeLists.txt +4 -1
- package/android/src/main/java/com/margelo/nitro/nitrolocationtracking/AirplaneModeMonitor.kt +72 -0
- package/android/src/main/java/com/margelo/nitro/nitrolocationtracking/MockLocationMonitor.kt +145 -0
- package/android/src/main/java/com/margelo/nitro/nitrolocationtracking/NitroLocationTracking.kt +75 -0
- package/cpp/HybridNitroLocationComplexLogicsCalculation.cpp +204 -0
- package/cpp/HybridNitroLocationComplexLogicsCalculation.hpp +29 -0
- package/ios/MockLocationMonitor.swift +120 -0
- package/ios/NitroLocationTracking.swift +29 -0
- package/lib/module/NitroLocationComplexLogicsCalculation.nitro.js +4 -0
- package/lib/module/NitroLocationComplexLogicsCalculation.nitro.js.map +1 -0
- package/lib/module/index.js +1 -2
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/NitroLocationComplexLogicsCalculation.nitro.d.ts +25 -0
- package/lib/typescript/src/NitroLocationComplexLogicsCalculation.nitro.d.ts.map +1 -0
- package/lib/typescript/src/NitroLocationTracking.nitro.d.ts +5 -0
- package/lib/typescript/src/NitroLocationTracking.nitro.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +3 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JHybridNitroLocationTrackingSpec.cpp +17 -0
- package/nitrogen/generated/android/c++/JHybridNitroLocationTrackingSpec.hpp +4 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrolocationtracking/HybridNitroLocationTrackingSpec.kt +26 -0
- package/nitrogen/generated/android/nitrolocationtracking+autolinking.cmake +1 -0
- package/nitrogen/generated/ios/c++/HybridNitroLocationTrackingSpecSwift.hpp +26 -0
- package/nitrogen/generated/ios/swift/HybridNitroLocationTrackingSpec.swift +4 -0
- package/nitrogen/generated/ios/swift/HybridNitroLocationTrackingSpec_cxx.swift +55 -0
- package/nitrogen/generated/shared/c++/HybridNitroLocationComplexLogicsCalculationSpec.cpp +25 -0
- package/nitrogen/generated/shared/c++/HybridNitroLocationComplexLogicsCalculationSpec.hpp +72 -0
- package/nitrogen/generated/shared/c++/HybridNitroLocationTrackingSpec.cpp +4 -0
- package/nitrogen/generated/shared/c++/HybridNitroLocationTrackingSpec.hpp +7 -0
- package/nitrogen/generated/shared/c++/LocationPoint.hpp +99 -0
- package/nitrogen/generated/shared/c++/TripMathStats.hpp +95 -0
- package/package.json +1 -1
- package/src/NitroLocationComplexLogicsCalculation.nitro.ts +37 -0
- package/src/NitroLocationTracking.nitro.ts +7 -0
- package/src/index.tsx +11 -1
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridNitroLocationComplexLogicsCalculationSpec.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/HybridObject.hpp>)
|
|
11
|
+
#include <NitroModules/HybridObject.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
// Forward declaration of `TripMathStats` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::nitrolocationtracking { struct TripMathStats; }
|
|
18
|
+
// Forward declaration of `LocationPoint` to properly resolve imports.
|
|
19
|
+
namespace margelo::nitro::nitrolocationtracking { struct LocationPoint; }
|
|
20
|
+
|
|
21
|
+
#include "TripMathStats.hpp"
|
|
22
|
+
#include "LocationPoint.hpp"
|
|
23
|
+
#include <vector>
|
|
24
|
+
#include <string>
|
|
25
|
+
|
|
26
|
+
namespace margelo::nitro::nitrolocationtracking {
|
|
27
|
+
|
|
28
|
+
using namespace margelo::nitro;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* An abstract base class for `NitroLocationComplexLogicsCalculation`
|
|
32
|
+
* Inherit this class to create instances of `HybridNitroLocationComplexLogicsCalculationSpec` in C++.
|
|
33
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
34
|
+
* @example
|
|
35
|
+
* ```cpp
|
|
36
|
+
* class HybridNitroLocationComplexLogicsCalculation: public HybridNitroLocationComplexLogicsCalculationSpec {
|
|
37
|
+
* public:
|
|
38
|
+
* HybridNitroLocationComplexLogicsCalculation(...): HybridObject(TAG) { ... }
|
|
39
|
+
* // ...
|
|
40
|
+
* };
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
class HybridNitroLocationComplexLogicsCalculationSpec: public virtual HybridObject {
|
|
44
|
+
public:
|
|
45
|
+
// Constructor
|
|
46
|
+
explicit HybridNitroLocationComplexLogicsCalculationSpec(): HybridObject(TAG) { }
|
|
47
|
+
|
|
48
|
+
// Destructor
|
|
49
|
+
~HybridNitroLocationComplexLogicsCalculationSpec() override = default;
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
// Properties
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
public:
|
|
56
|
+
// Methods
|
|
57
|
+
virtual TripMathStats calculateTotalTripStats(const std::vector<LocationPoint>& points) = 0;
|
|
58
|
+
virtual std::vector<LocationPoint> filterAnomalousPoints(const std::vector<LocationPoint>& points, double maxSpeedLimitMs) = 0;
|
|
59
|
+
virtual std::vector<LocationPoint> smoothPath(const std::vector<LocationPoint>& points, double toleranceMeters) = 0;
|
|
60
|
+
virtual double calculateBearing(double lat1, double lon1, double lat2, double lon2) = 0;
|
|
61
|
+
virtual std::string encodeGeohash(double latitude, double longitude, double precision) = 0;
|
|
62
|
+
|
|
63
|
+
protected:
|
|
64
|
+
// Hybrid Setup
|
|
65
|
+
void loadHybridMethods() override;
|
|
66
|
+
|
|
67
|
+
protected:
|
|
68
|
+
// Tag for logging
|
|
69
|
+
static constexpr auto TAG = "NitroLocationComplexLogicsCalculation";
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
} // namespace margelo::nitro::nitrolocationtracking
|
|
@@ -31,6 +31,7 @@ namespace margelo::nitro::nitrolocationtracking {
|
|
|
31
31
|
prototype.registerHybridMethod("forceSync", &HybridNitroLocationTrackingSpec::forceSync);
|
|
32
32
|
prototype.registerHybridMethod("isFakeGpsEnabled", &HybridNitroLocationTrackingSpec::isFakeGpsEnabled);
|
|
33
33
|
prototype.registerHybridMethod("setRejectMockLocations", &HybridNitroLocationTrackingSpec::setRejectMockLocations);
|
|
34
|
+
prototype.registerHybridMethod("onMockLocationDetected", &HybridNitroLocationTrackingSpec::onMockLocationDetected);
|
|
34
35
|
prototype.registerHybridMethod("addGeofence", &HybridNitroLocationTrackingSpec::addGeofence);
|
|
35
36
|
prototype.registerHybridMethod("removeGeofence", &HybridNitroLocationTrackingSpec::removeGeofence);
|
|
36
37
|
prototype.registerHybridMethod("removeAllGeofences", &HybridNitroLocationTrackingSpec::removeAllGeofences);
|
|
@@ -47,6 +48,9 @@ namespace margelo::nitro::nitrolocationtracking {
|
|
|
47
48
|
prototype.registerHybridMethod("getLocationPermissionStatus", &HybridNitroLocationTrackingSpec::getLocationPermissionStatus);
|
|
48
49
|
prototype.registerHybridMethod("requestLocationPermission", &HybridNitroLocationTrackingSpec::requestLocationPermission);
|
|
49
50
|
prototype.registerHybridMethod("onPermissionStatusChange", &HybridNitroLocationTrackingSpec::onPermissionStatusChange);
|
|
51
|
+
prototype.registerHybridMethod("openLocationSettings", &HybridNitroLocationTrackingSpec::openLocationSettings);
|
|
52
|
+
prototype.registerHybridMethod("isAirplaneModeEnabled", &HybridNitroLocationTrackingSpec::isAirplaneModeEnabled);
|
|
53
|
+
prototype.registerHybridMethod("onAirplaneModeChange", &HybridNitroLocationTrackingSpec::onAirplaneModeChange);
|
|
50
54
|
prototype.registerHybridMethod("getDistanceBetween", &HybridNitroLocationTrackingSpec::getDistanceBetween);
|
|
51
55
|
prototype.registerHybridMethod("getDistanceToGeofence", &HybridNitroLocationTrackingSpec::getDistanceToGeofence);
|
|
52
56
|
prototype.registerHybridMethod("showLocalNotification", &HybridNitroLocationTrackingSpec::showLocalNotification);
|
|
@@ -35,6 +35,8 @@ namespace margelo::nitro::nitrolocationtracking { struct TripStats; }
|
|
|
35
35
|
namespace margelo::nitro::nitrolocationtracking { enum class LocationProviderStatus; }
|
|
36
36
|
// Forward declaration of `PermissionStatus` to properly resolve imports.
|
|
37
37
|
namespace margelo::nitro::nitrolocationtracking { enum class PermissionStatus; }
|
|
38
|
+
// Forward declaration of `AccuracyLevel` to properly resolve imports.
|
|
39
|
+
namespace margelo::nitro::nitrolocationtracking { enum class AccuracyLevel; }
|
|
38
40
|
|
|
39
41
|
#include "LocationConfig.hpp"
|
|
40
42
|
#include "LocationData.hpp"
|
|
@@ -50,6 +52,7 @@ namespace margelo::nitro::nitrolocationtracking { enum class PermissionStatus; }
|
|
|
50
52
|
#include "TripStats.hpp"
|
|
51
53
|
#include "LocationProviderStatus.hpp"
|
|
52
54
|
#include "PermissionStatus.hpp"
|
|
55
|
+
#include "AccuracyLevel.hpp"
|
|
53
56
|
|
|
54
57
|
namespace margelo::nitro::nitrolocationtracking {
|
|
55
58
|
|
|
@@ -99,6 +102,7 @@ namespace margelo::nitro::nitrolocationtracking {
|
|
|
99
102
|
virtual std::shared_ptr<Promise<bool>> forceSync() = 0;
|
|
100
103
|
virtual bool isFakeGpsEnabled() = 0;
|
|
101
104
|
virtual void setRejectMockLocations(bool reject) = 0;
|
|
105
|
+
virtual void onMockLocationDetected(const std::function<void(bool /* isMockEnabled */)>& callback) = 0;
|
|
102
106
|
virtual void addGeofence(const GeofenceRegion& region) = 0;
|
|
103
107
|
virtual void removeGeofence(const std::string& regionId) = 0;
|
|
104
108
|
virtual void removeAllGeofences() = 0;
|
|
@@ -115,6 +119,9 @@ namespace margelo::nitro::nitrolocationtracking {
|
|
|
115
119
|
virtual PermissionStatus getLocationPermissionStatus() = 0;
|
|
116
120
|
virtual std::shared_ptr<Promise<PermissionStatus>> requestLocationPermission() = 0;
|
|
117
121
|
virtual void onPermissionStatusChange(const std::function<void(PermissionStatus /* status */)>& callback) = 0;
|
|
122
|
+
virtual void openLocationSettings(AccuracyLevel accuracy, double intervalMs) = 0;
|
|
123
|
+
virtual bool isAirplaneModeEnabled() = 0;
|
|
124
|
+
virtual void onAirplaneModeChange(const std::function<void(bool /* isEnabled */)>& callback) = 0;
|
|
118
125
|
virtual double getDistanceBetween(double lat1, double lon1, double lat2, double lon2) = 0;
|
|
119
126
|
virtual double getDistanceToGeofence(const std::string& regionId) = 0;
|
|
120
127
|
virtual void showLocalNotification(const std::string& title, const std::string& body) = 0;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// LocationPoint.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
11
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
16
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/JSIHelpers.hpp>)
|
|
21
|
+
#include <NitroModules/JSIHelpers.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
|
|
26
|
+
#include <NitroModules/PropNameIDCache.hpp>
|
|
27
|
+
#else
|
|
28
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
namespace margelo::nitro::nitrolocationtracking {
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A struct which can be represented as a JavaScript object (LocationPoint).
|
|
39
|
+
*/
|
|
40
|
+
struct LocationPoint final {
|
|
41
|
+
public:
|
|
42
|
+
double latitude SWIFT_PRIVATE;
|
|
43
|
+
double longitude SWIFT_PRIVATE;
|
|
44
|
+
double timestamp SWIFT_PRIVATE;
|
|
45
|
+
double speed SWIFT_PRIVATE;
|
|
46
|
+
double accuracy SWIFT_PRIVATE;
|
|
47
|
+
|
|
48
|
+
public:
|
|
49
|
+
LocationPoint() = default;
|
|
50
|
+
explicit LocationPoint(double latitude, double longitude, double timestamp, double speed, double accuracy): latitude(latitude), longitude(longitude), timestamp(timestamp), speed(speed), accuracy(accuracy) {}
|
|
51
|
+
|
|
52
|
+
public:
|
|
53
|
+
friend bool operator==(const LocationPoint& lhs, const LocationPoint& rhs) = default;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
} // namespace margelo::nitro::nitrolocationtracking
|
|
57
|
+
|
|
58
|
+
namespace margelo::nitro {
|
|
59
|
+
|
|
60
|
+
// C++ LocationPoint <> JS LocationPoint (object)
|
|
61
|
+
template <>
|
|
62
|
+
struct JSIConverter<margelo::nitro::nitrolocationtracking::LocationPoint> final {
|
|
63
|
+
static inline margelo::nitro::nitrolocationtracking::LocationPoint fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
64
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
65
|
+
return margelo::nitro::nitrolocationtracking::LocationPoint(
|
|
66
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "latitude"))),
|
|
67
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "longitude"))),
|
|
68
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "timestamp"))),
|
|
69
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "speed"))),
|
|
70
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "accuracy")))
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrolocationtracking::LocationPoint& arg) {
|
|
74
|
+
jsi::Object obj(runtime);
|
|
75
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "latitude"), JSIConverter<double>::toJSI(runtime, arg.latitude));
|
|
76
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "longitude"), JSIConverter<double>::toJSI(runtime, arg.longitude));
|
|
77
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "timestamp"), JSIConverter<double>::toJSI(runtime, arg.timestamp));
|
|
78
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "speed"), JSIConverter<double>::toJSI(runtime, arg.speed));
|
|
79
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "accuracy"), JSIConverter<double>::toJSI(runtime, arg.accuracy));
|
|
80
|
+
return obj;
|
|
81
|
+
}
|
|
82
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
83
|
+
if (!value.isObject()) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
jsi::Object obj = value.getObject(runtime);
|
|
87
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "latitude")))) return false;
|
|
91
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "longitude")))) return false;
|
|
92
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "timestamp")))) return false;
|
|
93
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "speed")))) return false;
|
|
94
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "accuracy")))) return false;
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// TripMathStats.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
11
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
16
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/JSIHelpers.hpp>)
|
|
21
|
+
#include <NitroModules/JSIHelpers.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
|
|
26
|
+
#include <NitroModules/PropNameIDCache.hpp>
|
|
27
|
+
#else
|
|
28
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
namespace margelo::nitro::nitrolocationtracking {
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A struct which can be represented as a JavaScript object (TripMathStats).
|
|
39
|
+
*/
|
|
40
|
+
struct TripMathStats final {
|
|
41
|
+
public:
|
|
42
|
+
double totalDistanceMeters SWIFT_PRIVATE;
|
|
43
|
+
double elapsedTimeMs SWIFT_PRIVATE;
|
|
44
|
+
double maxSpeedKmh SWIFT_PRIVATE;
|
|
45
|
+
double averageSpeedKmh SWIFT_PRIVATE;
|
|
46
|
+
|
|
47
|
+
public:
|
|
48
|
+
TripMathStats() = default;
|
|
49
|
+
explicit TripMathStats(double totalDistanceMeters, double elapsedTimeMs, double maxSpeedKmh, double averageSpeedKmh): totalDistanceMeters(totalDistanceMeters), elapsedTimeMs(elapsedTimeMs), maxSpeedKmh(maxSpeedKmh), averageSpeedKmh(averageSpeedKmh) {}
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
friend bool operator==(const TripMathStats& lhs, const TripMathStats& rhs) = default;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
} // namespace margelo::nitro::nitrolocationtracking
|
|
56
|
+
|
|
57
|
+
namespace margelo::nitro {
|
|
58
|
+
|
|
59
|
+
// C++ TripMathStats <> JS TripMathStats (object)
|
|
60
|
+
template <>
|
|
61
|
+
struct JSIConverter<margelo::nitro::nitrolocationtracking::TripMathStats> final {
|
|
62
|
+
static inline margelo::nitro::nitrolocationtracking::TripMathStats fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
63
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
64
|
+
return margelo::nitro::nitrolocationtracking::TripMathStats(
|
|
65
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "totalDistanceMeters"))),
|
|
66
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "elapsedTimeMs"))),
|
|
67
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxSpeedKmh"))),
|
|
68
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "averageSpeedKmh")))
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrolocationtracking::TripMathStats& arg) {
|
|
72
|
+
jsi::Object obj(runtime);
|
|
73
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "totalDistanceMeters"), JSIConverter<double>::toJSI(runtime, arg.totalDistanceMeters));
|
|
74
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "elapsedTimeMs"), JSIConverter<double>::toJSI(runtime, arg.elapsedTimeMs));
|
|
75
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "maxSpeedKmh"), JSIConverter<double>::toJSI(runtime, arg.maxSpeedKmh));
|
|
76
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "averageSpeedKmh"), JSIConverter<double>::toJSI(runtime, arg.averageSpeedKmh));
|
|
77
|
+
return obj;
|
|
78
|
+
}
|
|
79
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
80
|
+
if (!value.isObject()) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
jsi::Object obj = value.getObject(runtime);
|
|
84
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "totalDistanceMeters")))) return false;
|
|
88
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "elapsedTimeMs")))) return false;
|
|
89
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxSpeedKmh")))) return false;
|
|
90
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "averageSpeedKmh")))) return false;
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
} // namespace margelo::nitro
|
package/package.json
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
+
|
|
3
|
+
export interface LocationPoint {
|
|
4
|
+
latitude: number;
|
|
5
|
+
longitude: number;
|
|
6
|
+
timestamp: number;
|
|
7
|
+
speed: number;
|
|
8
|
+
accuracy: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface TripMathStats {
|
|
12
|
+
totalDistanceMeters: number;
|
|
13
|
+
elapsedTimeMs: number;
|
|
14
|
+
maxSpeedKmh: number;
|
|
15
|
+
averageSpeedKmh: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface NitroLocationComplexLogicsCalculation
|
|
19
|
+
extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
|
|
20
|
+
calculateTotalTripStats(points: LocationPoint[]): TripMathStats;
|
|
21
|
+
|
|
22
|
+
filterAnomalousPoints(
|
|
23
|
+
points: LocationPoint[],
|
|
24
|
+
maxSpeedLimitMs: number
|
|
25
|
+
): LocationPoint[];
|
|
26
|
+
|
|
27
|
+
smoothPath(points: LocationPoint[], toleranceMeters: number): LocationPoint[];
|
|
28
|
+
|
|
29
|
+
calculateBearing(
|
|
30
|
+
lat1: number,
|
|
31
|
+
lon1: number,
|
|
32
|
+
lat2: number,
|
|
33
|
+
lon2: number
|
|
34
|
+
): number;
|
|
35
|
+
|
|
36
|
+
encodeGeohash(latitude: number, longitude: number, precision: number): string;
|
|
37
|
+
}
|
|
@@ -43,6 +43,7 @@ export interface ConnectionConfig {
|
|
|
43
43
|
export type LocationCallback = (location: LocationData) => void;
|
|
44
44
|
export type ConnectionStateCallback = (state: ConnectionState) => void;
|
|
45
45
|
export type MessageCallback = (message: string) => void;
|
|
46
|
+
export type MockLocationCallback = (isMockEnabled: boolean) => void;
|
|
46
47
|
|
|
47
48
|
export interface GeofenceRegion {
|
|
48
49
|
id: string;
|
|
@@ -121,6 +122,7 @@ export interface NitroLocationTracking
|
|
|
121
122
|
// === Fake GPS Detection ===
|
|
122
123
|
isFakeGpsEnabled(): boolean;
|
|
123
124
|
setRejectMockLocations(reject: boolean): void;
|
|
125
|
+
onMockLocationDetected(callback: MockLocationCallback): void;
|
|
124
126
|
|
|
125
127
|
// === Geofencing ===
|
|
126
128
|
addGeofence(region: GeofenceRegion): void;
|
|
@@ -147,6 +149,11 @@ export interface NitroLocationTracking
|
|
|
147
149
|
getLocationPermissionStatus(): PermissionStatus;
|
|
148
150
|
requestLocationPermission(): Promise<PermissionStatus>;
|
|
149
151
|
onPermissionStatusChange(callback: PermissionStatusCallback): void;
|
|
152
|
+
openLocationSettings(accuracy: AccuracyLevel, intervalMs: number): void;
|
|
153
|
+
|
|
154
|
+
// === Device State Monitoring ===
|
|
155
|
+
isAirplaneModeEnabled(): boolean;
|
|
156
|
+
onAirplaneModeChange(callback: (isEnabled: boolean) => void): void;
|
|
150
157
|
|
|
151
158
|
// === Distance Utilities ===
|
|
152
159
|
getDistanceBetween(
|
package/src/index.tsx
CHANGED
|
@@ -12,11 +12,14 @@ const NitroLocationModule =
|
|
|
12
12
|
'NitroLocationTracking'
|
|
13
13
|
);
|
|
14
14
|
|
|
15
|
+
export const NitroLocationCalculations = NitroModules.createHybridObject<
|
|
16
|
+
import('./NitroLocationComplexLogicsCalculation.nitro').NitroLocationComplexLogicsCalculation
|
|
17
|
+
>('NitroLocationComplexLogicsCalculation');
|
|
18
|
+
|
|
15
19
|
export default NitroLocationModule;
|
|
16
20
|
export { requestLocationPermission } from './requestPermission';
|
|
17
21
|
export { LocationSmoother } from './LocationSmoother';
|
|
18
22
|
export { shortestRotation, calculateBearing } from './bearing';
|
|
19
|
-
// export * from './db'
|
|
20
23
|
export type {
|
|
21
24
|
NitroLocationTracking,
|
|
22
25
|
LocationData,
|
|
@@ -33,8 +36,15 @@ export type {
|
|
|
33
36
|
ProviderStatusCallback,
|
|
34
37
|
PermissionStatus,
|
|
35
38
|
PermissionStatusCallback,
|
|
39
|
+
MockLocationCallback,
|
|
36
40
|
} from './NitroLocationTracking.nitro';
|
|
37
41
|
|
|
42
|
+
export type {
|
|
43
|
+
NitroLocationComplexLogicsCalculation,
|
|
44
|
+
LocationPoint,
|
|
45
|
+
TripMathStats,
|
|
46
|
+
} from './NitroLocationComplexLogicsCalculation.nitro';
|
|
47
|
+
|
|
38
48
|
export function useDriverLocation(config: LocationConfig) {
|
|
39
49
|
const [location, setLocation] = useState<LocationData | null>(null);
|
|
40
50
|
const [isMoving, setIsMoving] = useState(false);
|