Quick Start
This guide makes implementation our SDK to your app as pleasant as possible.
Minimal requirements
- Android device running API 23 and above
- Since this is offline maps-based SDK, sufficent space on internal or external storage is required
Adding library to the project
You can choose between Maven repository and manual offline managing.
Maven repository (to be done)
Add this piece of code to settings.gradle
dependencyResolutionManagement {
..
repositories {
..
maven {
url "https://sdk.mapfactor.com/repo/release"
credentials {
username "user"
password "repo"
}
}
Configure your build.gradle
dependencies {
implementation "com.mapfactor:sdk:0.28.4"
}
Manual managing
To add SDK to your Android Studio project, follow the official manual on Google developer websites for adding .aar
file. Select mpfc-sdk-x.y.z-production.aar
.
Check your app’s build.gradle
file:
implementation files('path_to_sdk/mpfc-sdk-x.y.z-production.aar')
Adding to the layout
Jetpack Compose
In case of using Jetpack Compose, check Inter-op with XML inter-op docs by Google. Add implementation 'com.google.android.material:material:x.y.z'
for back compatibility. Use FragmentActivity instead of a ComponentAcitivty successor to support our Fragment.
MapView element
AndroidView(
modifier = Modifier.fillMaxSize(),
factory = { context ->
MapView(context).apply {
}
},
update = {
}
)
Fragment element
AndroidView(
modifier = Modifier.fillMaxSize(),
factory = { context ->
MapView(context).apply {
}
},
update = {
}
)
View-based system
For layout implementation, there are two options - direct XML view containing MapFragment on background or inserting a MapFragment with FragmentContainerView.
MapView element
<com.mapfactor.sdk.map.MapView
android:id="@+id/map_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Fragment element
<androidx.fragment.app.FragmentContainerView
android:id="@+id/map_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.mapfactor.sdk.map.MapFragment"/>
Initialization
To properly init the SDK, use MpfcEngine.initβ(..)
method. You will need to add permissions to access device location to AndroidManifest.xml
as follows.
AndroidManifest.xml
<manifest..>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<manifest>
TestApplication.kt
// get path
val sdkDataPath = getExternalFilesDir(null).toString()
// get renderer
val rendererName: RendererName = RendererName.HARDWARE
// get map data provider
val mapDataProvider: ProviderName = ProviderName.OSM
//get language
val lang = "en"
MpfcEngine.init(this, sdkDataPath, mapDataProvider, rendererName, lang, object :
MpfcEngine.InitListener {
override fun onLocationPermissionNotGranted() {
// notify an activity to make a request for location permission,
// e.g. using broadcast intent
}
override fun onEngineInitStatusChanged(initStatus: MpfcEngine.InitStatus) {
// log
}
override fun onEngineInitFinished(initStatusResult: MpfcEngine.InitResult) {
if (result == MpfcEngine.InitResult.SUCCESS) {
//HURAYYY, do whatever you want, e.g.
initActiveVehicle()
getAllAvailableVehicles()
setCurrentLanguage()
} else if (result == MpfcEngine.InitResult.FAILED_DEVICE_NOT_ACTIVATED
|| result == MpfcEngine.InitResult.FAILED_SDK_NOT_LICENSED) {
//oops, activate device
activateDevice()
}
}
})
fun activateDevice() {
MpfcEngine.getInstance().activateDevice(
getApplication(),
"AAAAA-BBBBB-CCCCC-DDDDD-EEEEE"
) { activationResult: MpfcEngine.ActivationResult ->
val succeeded =
activationResult == MpfcEngine.ActivationResult.SUCCEEDED ||
activationResult == MpfcEngine.ActivationResult.ALREADY_ACTIVATED
...
}
}
Add dependencies to a build.gradle:
implementation "androidx.compose.ui:ui-viewbinding:$compose_version"
implementation 'androidx.fragment:fragment-ktx:1.4.1'
buildFeatures {
viewBinding true
}
implementation ‘androidx.constraintlayout:constraintlayout:2.1.4’ taky important onEngineRestarted, vse az tady pro MpfcEngine.getAppDataManagerModule() .downloadAppData a MpfcEngine.getAppDataManagerModule() .deleteAppData