Geofencing

Last Updated on : 2024-07-10 09:09:14download

This topic describes the geofencing features.

Concepts

LBS

Location-based services (LBS) are software services that use geographic data and information to provide services to users. With the control database, the mobile client can access users’ geographic coordinates through the wireless communication network or satellite navigation system. This information is then integrated with other data to offer location-based services.

Geofencing

Geofencing is a new LBS application that creates a virtual perimeter around a physical location. Like a real fence, a geofence creates a separation between that location and the area around it. Unlike a real fence, it can detect movement inside the virtual boundary. When a device enters or leaves a specific area, users will receive notifications. Geofencing technology allows location-based social networks to automatically check users in when they enter a specific area.

Geofencing features

The geofence center is typically located where the vehicle was last locked and changes as the vehicle moves. When the vehicle is locked, it reports its current location. An alert will be triggered if the location deviates beyond the specified radius. When the vehicle exits the geofence boundary, an alert will be triggered as specified.

Geofencing classes

Class (protocol) Description
IODGeofenceService Geofencing services
GeofenceResultInfoBean The entity class for the returned geofencing service information.
GeofenceInfoBean The entity class for the geofencing setting parameters.

Implement geofencing

UserMobile AppCloudVehicleGeofencing enabledEnable geofencingEnabled successfullyGeofencing activatedReport GPS when lockingReport GPS after lockingQuery vehicle locking status and location informationThe locked vehicle leaves the geofenceTrigger an alertUserMobile AppCloudVehicle

Check for geofencing enablement

Request the current geofencing information, including the on/off status and radius.

API description

/**
 * Get geofencing information
 * @param devId  The device ID
 * @param listener  Callback
 */
fun getGeofenceInfoWithDevID(
  devId: String,
  listener: IThingResultCallback<GeofenceResultInfoBean>
)

Example

private void getGeofenceInfoWithDevID(String deviceId) {
  OutdoorUtils.getGeofenceInfoWithDevID(deviceId, new IThingResultCallback<GeofenceResultInfoBean>() {
    @Override
    public void onSuccess(GeofenceResultInfoBean result) {
      showToast("getGeofenceInfoWithDevID success");
    }

    @Override
    public void onError(String errorCode, String errorMessage) {
      showToast("onError code=" + errorCode + " message=" + errorMessage);
    }
  });
}

Data model of GeofenceResultInfoBean

{
  "deviceId": "vdevo162814799088537",
  "deviceInfo": {
    "geofenceInfo": {
      "fenceRadius": 200,                 // Radius of a circular fence
      "fenceAppNotice": "app,sms,phone", // Alert information
      "open": true,                       // Geofencing feature on/off
      "lockDpCode": "blelock_switch",     // DP code for locking status
      "lockValue": "0"                    // The rule for determining the locking status. Equaling this value indicates locked status.
    }
  }
}
Field Type Description
fenceRadius Int The radius of the circular geofence.
fenceAppNotice String The alert message.
open Boolean Whether geofencing is enabled, true for enabled.
lockDpCode String The DP code of the locking status, fixed to blelock_switch.
lockValue String The DP value of the locking status.

Set a geofence

API description

/**
 * Set a geofence
 * @param devId  The device ID
 * @param geofenceInfoBean  The geofencing information
 * @param listener  Callback
 */
fun setGeofenceWithRequestModel(
  devId: String,
  geofenceInfoBean: GeofenceInfoBean,
  listener: IThingResultCallback<Boolean>
)

Example

private void setGeofenceWithRequestModel(String deviceId) {
  GeofenceInfoBean geofenceInfoBean = new GeofenceInfoBean();
  geofenceInfoBean.setFenceAppNotice("app");
  geofenceInfoBean.setFenceRadius(50);
  geofenceInfoBean.setOpen(true);
  geofenceInfoBean.setLockDpCode("blelock_switch");
  geofenceInfoBean.setLockValue("false");
  OutdoorUtils.setGeofenceWithRequestModel(deviceId, geofenceInfoBean, new IThingResultCallback<Boolean>() {
    @Override
    public void onSuccess(Boolean result) {
      showToast("setGeofenceWithRequestModel success="+result);
    }

    @Override
    public void onError(String errorCode, String errorMessage) {
      showToast("onError code=" + errorCode + " message=" + errorMessage);
    }
  });
}

Data model of GeofenceInfoBean

{
  "fenceRadius": 200,
  "fenceAppNotice": "app,sms,phone",
  "open": true,
  "lockDpCode": "blelock_switch",
  "lockValue": "0"
}
Field Type Description
fenceRadius Int The radius of the circular geofence.
fenceAppNotice String The alert type, with multiple options separated by a comma (,).
  • app: App notification
  • sms: SMS message
  • phone: Phone call
Example: "app,sms" indicates the app notification and SMS message are enabled.
open Boolean Whether geofencing is enabled, true for enabled.
lockDpCode String The DP code of the locking status, fixed to blelock_switch.
lockValue String The DP value of the locking status.

The lockValue may vary because lockDpCode can be customized. For example, blelock_switch can be of Boolean or integer type. Read the data type before requesting the lock value.

  • If blelock_switch is of Boolean type and false means locked, send the string "false".
  • If blelock_switch is of integer type and 1 means locked, send the string "1".