External control of MegaTracker sensors
By default, MegaTracker automatically manages the listening interfaces for accelerometer and GNSS data. However, in certain complex application scenarios, developers may need to manually control the enabling and disabling of these interfaces to achieve finer-grained power management or permission control.
Before you begin
- Learn about MegaTracker concepts and workflow
External control constraints
When creating a session MegaTrackerConfigs, you can configure sensor listening interfaces via MegaTrackerSensorOptions.
| Parameter name | Type | Default value | Description |
|---|---|---|---|
| isAcceExternalControl | boolean |
false |
Whether the accelerometer is controlled externally (by the developer). |
| isGeoExternalControl | boolean |
false |
Whether GNSS data is controlled externally (by the developer). |
Tip
Applicable scenario: If your application does not directly subscribe to sensor data except for Mega functions, it is recommended to keep the default value false and let Mega handle it automatically.
When the above parameters are set to true, developers must strictly follow the following call sequence:
- Startup process
Before calling start(options), you must ensure the corresponding sensor monitoring has been manually started:
Accelerometer: Call wx.startAccelerometer.
GNSS: Call wx.startLocationUpdate.
Stopping process
After calling stop(), you can then turn off the corresponding sensor monitoring:
Accelerometer: Call wx.stopAccelerometer.
GNSS: Call wx.stopLocationUpdate.
Caution
Conflict warning: If set to false (Mega managed), do not call the WeChat native stop sensor interface during the session running, otherwise it will cause data interruption.
const megaTrackerSensorOptions: easyar.MegaTrackerSensorOptions = {
isAcceExternalControl: false,
isGeoExternalControl: true
};
const megaTrackerConfigs: easyar.MegaTrackerConfigs = {
access: apiKeyAccess,
options: megaTrackerSensorOptions
};
session = megaComponent.createSession(megaTrackerConfigs);
This example demonstrates how to externally control the start and stop of WeChat location data monitoring. Before calling start(options), you need to call wx.startLocationUpdate to start WeChat location data monitoring.