Monitor Woosmap assets

Monitor Woosmap assets with Geofence using iOS SDK and Woosmap Search API

  1. Monitor Woosmap Search API assets by automatically generate geofence around its

Monitor Woosmap Search API assets by automatically generate geofence around its

You need a Private API key to request the Woosmap Search API.

To monitor more than 10 points of interest, it is recommended to use Woosmap Search API and load these POIs as Woosmap assets.

Indeed, Search requests help monitoring the approach to some assets you want to monitor. Assets monitoring starts by monitoring the 20 nearest assets and the SDK regularly refresh this list of 20 assets by requesting the Woosmap Search API

To create a circular region around the nearest result of the Search API request, use the passive tracking profile or enable the tracking properties searchAPICreationRegionEnable:

WoosmapGeofencing.shared.setSearchAPICreationRegionEnable(enable: true)

But first you have to set keys and set a delegate to monitor result of the SearchAPI request:

let dataPOI = DataPOI()

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        // Set Woosmap API Private key
        WoosmapGeofencing.shared.setWoosmapAPIKey(key: WoosmapKey)

         // Set delegate of protocol POI 
        WoosmapGeofencing.shared.getLocationService().searchAPIDataDelegate = DataPOI()

        return true
}
// Implement the SearchAPI delegate class for allowing the SDK to interact with Woosmap Search API

public class DataPOI: SearchAPIDelegate {
    public init() {}

    // handle search API response
    public func searchAPIResponse(poi: POI) {
    }

    // handle search API error message
    public func searchAPIError(error: String) {

    }

    // retrieve POI data
    public func readPOI() -> [POI] {
        return POIs.getAll()
    }

    // retrieve a POI linked to a specific locationId
    func getPOIbyLocationID(locationId: String) -> POI? {
        return POIs.getPOIbyLocationID(locationId: locationId)
    }

    // remove all POI from device database
    public func erasePOI() {
        POIs.deleteAll()
    }

}

Region callbacks are triggered each time a user enters or exits a geofence:

import WoosmapGeofencing

public class DataRegion: RegionsServiceDelegate {

    // the didEnterPOIRegion() is called when a user enters in the geofence 
    public func didEnterPOIRegion(POIregion: Region) {
        
        // check first if the POIregion.origin is equal to "POI" 
        if POIregion.origin == "POI"
        {
            // retrieve POI data from the device database
            if let POI = POIs.getPOIbyIdStore(idstore: POIregion.identifier ?? "") as POI? {
                print("Woosmap Geofencing Events: woos_geofence_entered_event - POI name:" + POI.name);
            }
            else {
                // error: Related POI doesn't exist
            }
        }
    }

In the didExitPOIRegion method, an additional data is provided by the regionLog object: spentTime It represents the time spent in the geofence between the entry event and the exit event.

Radius of POI

Manually define the radius value:

WoosmapGeofencing.shared.setPoiRadius(radius: 500.0)

or choose the user_properties subfield that corresponds to radius value of the Geofence:

WoosmapGeofencing.shared.setPoiRadius(radius: "radiusPOI")
Was this article helpful?
Have more questions? Submit a request