Skip to main content
GuidesAPI ReferenceExamples

Social Report

|

In this guide you will learn how to send a social report from within an app. An interactive map is displayed, and the social report is sent automatically as soon as the map is ready.

Social report sent

Map Integration

In this example, the social report is sent automatically when the app is started, so long as a real or mock device position, such as GPS, is available.

When the map is loaded, SdkSettings.onMapDataReady follow position is activated so the camera follows the position of the device, in case it is in a car in motion, for example gemSurfaceView.mapView?.followPosition()

A function, waitForNextImprovedPosition(), is called to wait until the first good quality position of the device is received from the position sensor, such as GPS.

When a good position has been obtained, the social report is sent automatically: submitReport()

MainActivity.kt
override fun onCreate(savedInstanceState: Bundle?)
{
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
gemSurfaceView = findViewById(R.id.gem_surface)
statusText = findViewById(R.id.status_text)
SdkSettings.onMapDataReady = { isReady ->
if (isReady)
{
// Defines an action that should be done
// when the world map is ready (Updated/ loaded).
SdkCall.execute {
gemSurfaceView.mapView?.followPosition()
waitForNextImprovedPosition {
submitReport()
}
}
}
}
SdkSettings.onApiTokenRejected = {
showDialog("TOKEN REJECTED")
}
...
}

Report Functionality

The PositionListener instance is created and added to the PositionService.addListener() to be called when a good position EDataType.ImprovedPosition is received from the GPS sensor.

When that happens, the function passed in is called automatically, that is, the onEvent() parameter, which is submitReport().

In this case, causing the social report to be sent upon reading the first valid device position from the sensor.

MainActivity.kt
private fun waitForNextImprovedPosition(onEvent: (() -> Unit))
{
positionListener = PositionListener {
if (it.isValid())
{
Util.postOnMain { showStatusMessage("On valid position") }
onEvent()
PositionService.removeListener(positionListener)
}
}
PositionService.addListener(positionListener, EDataType.ImprovedPosition)
// listen for first valid position to start the nav
Util.postOnMain { showStatusMessage("Waiting for valid position", true) }
}

The submitReport() function creates the report: val prepareIdOrError = SocialOverlay.prepareReporting() and if this fails, an error message is displayed in a dialog box.

Otherwise, the report, stored in prepareIdOrError is sent: val error = SocialOverlay.report(prepareIdOrError, subCategory.uid, socialReportListener)

If sending fails, a dialog box is displayed, otherwise, a status message indicating that the report was sent is displayed at the bottom of the viewport.

MainActivity.kt
private fun submitReport() = SdkCall.execute
{
val overlayInfo = SocialOverlay.reportsOverlayInfo ?: return@execute
val countryISOCode = MapDetails().isoCodeForCurrentPosition ?: return@execute
val categories = overlayInfo.getCategories(countryISOCode) ?: return@execute
val mainCategory = categories[0] // Police
val subcategories = mainCategory.subcategories ?: return@execute
val subCategory = subcategories[0] // My side
val prepareIdOrError = SocialOverlay.prepareReporting()

if (prepareIdOrError <= 0)
{
val errorMsg = if (prepareIdOrError == GemError.NotFound
|| prepareIdOrError == GemError.Required)
{
"Prepare error: ${GemUtil.getUIString(EStringIds.eStrGPSAccuracyIsNotGoodEnough)}"
}
else
{
"Prepare error: ${GemError.getMessage(prepareIdOrError)}"
}
Util.postOnMain { showDialog(errorMsg) }
return@execute
}
val error = SocialOverlay.report(prepareIdOrError, subCategory.uid, socialReportListener)
if (GemError.isError(error))
{
Util.postOnMain { showDialog("Report Error: ${GemError.getMessage(error)}") }
}
else
{
Util.postOnMain { showStatusMessage("Report Sent!") }
}
}