Cordova plugin for bringing situm indoor positioning technology to hybrid apps
Situm Wayfinding for Capacitor and Cordova. Integrate plug&play navigation experience with floorplans, POIs, routes and turn-by-turn directions in no time. With the power of Situm.
This plugin has two parts:
The base SDK, the building blocks that allow you to:
A full featured and easy to integrate UI component (<map-view>
) that allows you to:
Please refer to CHANGELOG.md for a list of notables changes for each version of the plugin.
You can also see the tags on this repository.
You will need to sign a Contributor License Agreement (CLA) before making a submission. Learn more here.
Situm Cordova Plugin is licensed under MIT License. See LICENSE.txt file for further details.
[!NOTE]
This plugin is currently under development. There may be methods not implemented yet. Also there may be some API changes as development progresses.
Log in into your Situm Account. This key is generated in Situm Dashboard. Return true if apiKey was set successfully, otherwise false
cordova.plugins.Situm.setApiKey('SITUM_EMAIL', 'SITUM_API_KEY');
Provides user’s email and password. Return true if apiKey was set successfully, otherwise false
cordova.plugins.Situm.setUserPass('SITUM_EMAIL', 'SITUM_USER_PASS');
Set the remote configuration state which allows to use the configuration (location request) stored on the web to find the location of the user.
cordova.plugins.Situm.setUseRemoteConfig(true);
Sets the maximum age of a cached response in seconds.
cordova.plugins.Situm.setCacheMaxAge(1 * 60 * 60); // 1 hour
[!WARNING]
This method is deprecated, instead use requestLocationUpdates.
Starts the positioning system. In the success callback it can return:
locationOptions = {
buildingIdentifier = "BUILDING_ID"
};
cordova.plugins.Situm.startPositioning(locationOptions, (res: any) => {
if (res && res.statusName) {
// Returns location status
}
if (res && res.position) {
// Return location object
}
}, (err: any) => {
//Return error as an string.If this happens the positioning is stopped
});
Starts the positioning system. You can customize the positioning system by specifying a LocationRequest in the method parameters.
Use onLocationUpdate() to receive updates of the user’s location,
onLocationStatus() to receive updates of the positioning status
and onLocationError() to receive the possible errors that take place when positioning.
cordova.plugins.Situm.requestLocationUpdates(
{
buildingIdentifier = "YOUR_BUILDING_IDENTIFIER"
});
Stop the positioning system.
This method returns a promise, so use the .then() and .catch() methods to know the result.
cordova.plugins.Situm.removeUpdates()
.then(() => {
// Positioning system has stopped successfully.
})
.catch((err: any) => {
// Error while stopping the positioning system.
});
Use this callback to stay aware about the user’s Location.
cordova.plugins.Situm.onLocationUpdate((location: any) => {
console.log('The user has moved to: ' + location.position);
});
Use this callback to stay aware about the LocationStatus of the positioning system.
cordova.plugins.Situm.onLocationStatus((status: string) => {
console.log('New positioning status: ' + status);
});
Use this callback to stay aware about the errors the user might face when the positioning system starts.
See onLocationError().
cordova.plugins.Situm.onLocationError((err: any) => {
console.log('Error received when positioning: ' + err);
});
[!WARNING]
This method is deprecated, instead use removeUpdates.
Stop the positioning system on current active listener.
cordova.plugins.Situm.stopPositioning();
Download all the buildings for the current user.Returns an array of buildings
cordova.plugins.Situm.fetchBuildings(
(res: any) => {
// Return an array of buildings
},
(err: any) => {
// returns error string
}
);
Download the information (floors, pois, …) of a building
cordova.plugins.Situm.fetchBuildingInfo(
building,
(res: any) => {
// Return the buildingInfo
},
(err: any) => {
// returns error string
}
);
Download all the floors of a building.
cordova.plugins.Situm.fetchFloorsFromBuilding(
building,
(res: any) => {
// Return an array of floors
},
(err: any) => {
// returns error string
}
);
Download the indoor POIs of a building.
cordova.plugins.Situm.fetchIndoorPOIsFromBuilding(
building,
(res: any) => {
// Return an array of indoor POIs
},
(err: any) => {
// returns error string
}
);
Download the outdoor POIs of a building.
cordova.plugins.Situm.fetchOutdoorPOIsFromBuilding(
building,
(res: any) => {
// Return an array of outdoor POIs
},
(err: any) => {
// returns error string
}
);
Download the events of a building.
cordova.plugins.Situm.fetchEventsFromBuilding(
building,
(res: any) => {
// Return an array of events
},
(err: any) => {
// returns error string
}
);
Get all POI Categories, download and cache their icons asynchronously.
cordova.plugins.Situm.fetchPoiCategories(
(res: any) => {
// Return an array of POI categories
},
(err: any) => {
// returns error string
}
);
Download the map image of a floor.
cordova.plugins.Situm.fetchMapFromFloor(
floor,
(res: any) => {
// Return an image as an string encoded in Base64
},
(err: any) => {
// returns error string
}
);
Get the normal category icon for a POICategory.
cordova.plugins.Situm.fetchPoiCategoryIconNormal(
category,
(res: any) => {
// Return an image as an string encoded in Base64
},
(err: any) => {
// returns error string
}
);
Get the selected category icon for a POICategory.
cordova.plugins.Situm.fetchPoiCategoryIconSelected(
category,
(res: any) => {
// Return an image as an string encoded in Base64
},
(err: any) => {
// returns error string
}
);
Get all geofences from the building.
cordova.plugins.Situm.fetchGeofencesFromBuilding(
building,
(res: any) => {
// Return an array of geofences
},
(err: any) => {
// returns error string
}
);
Invalidate all the resources in the cache.
cordova.plugins.Situm.invalidateCache();
Calculates a route between two points. This route is the one that will be used when you call requestNavigationUpdates. If this method is called multiple times the last Route will be used.
You can change the options to generate the Route with DirectionOptions
Returns a Route
directionRequest = [
building, // Building in which you're positioning
from, // Point where you want to start the route. You can pass a Point or a Location
to, // Point where you want to finish the route
{} // Options to generate the route
];
cordova.plugins.Situm.requestDirections(
directionsRequest,
(route: any) => {
//Return a Route
},
(err: any) => {
// returns error string
}
);
Necessary step to request progress. Alone this method does not provide progress object. You must feed navigation API with location, as indicated on updateNavigationWithLocation section.
When you start feeding locations you can receive NavigationProgress or other of the results described below
// Navigation request with example values
navigationRequest = [
(distanceToGoalThreshold = 10),
(distanceToFloorChangeThreshold = 5)
];
cordova.plugins.Situm.requestNavigationUpdates(
navigationRequest,
(navigation: any) => {
/**
* This callback can return four different things:
* 1. A message notifying about the success starting the navigation
* 2. A json with the NavigationProgress. The Json will also have a field "type" with the value "progress" so you can know when this happens.
* 3. A json with the field "type" and the value "destinationReached". This happens when the navigation finish because you reached the end.
* 4. A json with the field "type" and the value "userOutsideRoute". This happens when the user deviate from the route. You can notify them so they return to the correct path.
*/
},
(error: any) => {
//returns error string
}
);
Usually, position variable should be one of the locations provided by the system on the startPositioning function.
cordova.plugins.Situm.updateNavigationWithLocation(currentLocation);
When you are no longer interested on Navigation Updates you should call this method to remove internal allocated resources.
cordova.plugins.Situm.removeNavigationUpdates();
Emits the real time location of devices
const request = {
building: building, //Building in which you want to be notified
pollTime: 3000 // time in milliseconds
};
cordova.plugins.Situm.SitumPlugin.requestRealTimeUpdates(
request,
(locations: any) => {
// returns the locations of the other devices in real time
},
(error: any) => {
// returns error string
}
);
When you are no longer interested on realtime location Updates you should call this method to remove internal allocated resources.
cordova.plugins.Situm.removeRealTimeUpdates();
Get notified about users entering geofences. Take into account:
trainer_metadata
custom field configured in the dashboard) won’t be notified.
cordova.plugins.Situm.onEnterGeofences((geofences: any) => {
// Returns an array of geofences
// e.g. [{"polygonPoints": [], "customFields": {}, "updatedAt": "Thu Jan 01 01:00:00 +0100 1970", "buildingIdentifier": "1234", "floorIdentifier": "123456", "code": "", "createdAt": "Thu Jan 01 01:00:00 +0100 1970", "infoHtml": "", "name": "My Geofence", "identifier": "12345678-aaaa-bbbb-cccc-12345678abcd"}]
});
Get notified about exiting geofences. Take into account the considerations described at onEnterGeofences.
cordova.plugins.Situm.onExitGeofences((geofences: any) => {
// Returns an array of geofences
// e.g. [{"polygonPoints": [], "customFields": {}, "updatedAt": "Thu Jan 01 01:00:00 +0100 1970", "buildingIdentifier": "1234", "floorIdentifier": "123456", "code": "", "createdAt": "Thu Jan 01 01:00:00 +0100 1970", "infoHtml": "", "name": "My Geofence", "identifier": "12345678-aaaa-bbbb-cccc-12345678abcd"}]
});
Get notified about the \
cordova.plugins.MapView.onLoad((controller: any) => {
// Once the MapView was loaded you can start managing our map by:
// 1. Sending actions like selecting or navigating to a poi in a building:
// controller.selectPoi('YOUR_POI_IDENTIFIER');
// controller.navigateToPoi('YOUR_POI_IDENTIFIER');
// 2. Listen to events that take place inside our map like a poi being selected or deselected:
controller.onPoiSelected((poiSelectedResult: any) => {
console.log('EXAMPLE> onPoiSelected -> ', poiSelectedResult);
});
controller.onPoiDeselected((poiDeselectedResult: any) => {
console.log('EXAMPLE> onPoiDeselected -> ', poiDeselectedResult);
});
});
Select a POI in the map.
cordova.plugins.MapView.onLoad((controller: any) => {
// Once the MapView was loaded you can select a POI in our map by calling:
controller.selectPoi('YOUR_POI_IDENTIFIER');
});
Navigate to a POI in the map when positioning indoors inside a building.
cordova.plugins.MapView.onLoad((controller: any) => {
// Once the MapView was loaded you can navigate to a POI in our map.
// Make sure to call this method once the user is positioning indoors in your building,
// otherwise this method will have no effect.
controller.navigateToPoi('YOUR_POI_IDENTIFIER');
// controller.navigateToPoi("YOUR_POI_IDENTIFIER", "CHOOSE_SHORTEST");
});
Listen to the selection event of a POI.
cordova.plugins.MapView.onLoad((controller: any) => {
// Once the MapView was loaded you can listen to a POI being selected.
controller.onPoiSelected((poiSelectedResult: any) => {
console.log('EXAMPLE> onPoiSelected -> ', poiSelectedResult);
});
});
Listen to listen to a POI being deselected.
cordova.plugins.MapView.onLoad((controller: any) => {
// Once the MapView was loaded you can listen to a POI being deselected.
controller.onPoiDeselected((poiDeselectedResult: any) => {
console.log('EXAMPLE> onPoiDeselected -> ', poiDeselectedResult);
});
});
1. Install mocha and expect.js:
```javascript
npm install mocha --save
npm install expect.js --save
```
2. In js tests folder run:
mocha test
Situm SDK for Android now compiles and targets sdkVersion 31 (Android 12). To work properly on Android 12 devices and above, the host app must:
config.xml
file, add <preference name="android-targetSdkVersion" value="31" ></preference>
to the Android platform configuration.ACCESS_COARSE_LOCATION
, BLUETOOTH_SCAN
and BLUETOOTH_CONNECT
(plus ACCESS_FINE_LOCATION
if you are using Global Mode). Remember to also add them to the Android platform section of your config.xml
file:
<config-file parent="/manifest" target="AndroidManifest.xml">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" ></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" ></uses-permission>
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" ></uses-permission>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" ></uses-permission>
</config-file>
android:exported="true"
to all the intent-filtered components of your AndroidManifest.xml
file. You can add the following configuration to your config.xml
to automate this process:
<edit-config
file="app/src/main/AndroidManifest.xml"
target="/manifest/application/activity[@android:name='MainActivity']"
mode="merge">
<activity android:exported="true"></activity>
</edit-config>
widget
root element of your config.xml
file declares the Android namespace:
<widget id="..." version="..."
...
xmlns:android="http://schemas.android.com/apk/res/android">
This plugin is compatible with Capacitor 3.0.
Issue: In iOS, there is a known issue with capacitor-cli 3.2.5 and static cordova plugins https://github.com/ionic-team/capacitor/issues/5142. To solve it use a different version of capacitor cli.
If the problem persists, add this plugin to the staticPlugins
section of your capacitor.config.json
file:
{
"cordova": {
"staticPlugins": ["@situm/cordova"]
}
}
More info is available at our Developers Page.
For any question or bug report, please send an email to support@situm.es