MapSDK - Getting started
Installation
Before starting to develop your application with the WemapSDKs, you'll need to configure your credentials and add the SDK as a dependency.
Add the dependency
Add the WemapSDKs to your app
In your module level Gradle file (usually
project/module/build.gradle.kts
orproject/module/build.gradle
), add the dependency for the WemapSDK library for Android.dependencies {
// Add the dependency for the WemapMapSDK library
implementation "com.getwemap.sdk:map:<version>"
}Make sure that your project's
minSdkVersion
is at API 21 or higher.android {
...
defaultConfig {
minSdkVersion 21
}
}Because you've edited your Gradle files, Android Studio will ask you whether you want to sync the Gradle files. You can sync now.
Add a map
Open the activity you’d like to add a map to and use the code below.
To make it work you should provide mapID
and token
to the mapData request.
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.getwemap.example.map.databinding.ActivityMainBinding
import com.getwemap.sdk.map.WemapMapSDK
import com.mapbox.mapboxsdk.Mapbox
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
val mapView get() = binding.mapView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Mapbox.getInstance(applicationContext)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
val request = WemapMapSDK.instance
.mapData(19158, "GUHTU6TYAWWQHUSR5Z5JZNMXX") // here you have to specify your mapID and token
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
mapView.mapData = it
}, {
println("Failed to get map data with error - ${it.message}")
})
}
}
Open the activity’s XML layout file and add the following:
<com.getwemap.sdk.map.WemapMapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
The WemapMapView contains its own lifecycle methods for managing Android's OpenGL lifecycle, which must be called directly from the containing Activity. For your app to correctly call the WemapMapView's lifecycle methods, you must override the following lifecycle methods in the Activity that contains the WemapMapView and call the respective WemapMapView method. The following lifecycle methods must be overridden and include the matching WemapMapView method. If you're using a fragment, call mapview.onDestroy()
inside the fragment's onDestroyView()
method rather than inside onDestroy()
.
override fun onStart() {
super.onStart()
mapView.onStart()
}
override fun onResume() {
super.onResume()
mapView.onResume()
}
override fun onPause() {
super.onPause()
mapView.onPause()
}
override fun onStop() {
super.onStop()
mapView.onStop()
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
mapView.onSaveInstanceState(outState)
}
override fun onLowMemory() {
super.onLowMemory()
mapView.onLowMemory()
}
override fun onDestroyView() {
super.onDestroyView()
mapView.onDestroy()
}
Examples
You can find additional examples for the WemapSDKs on GitHub. Clone the repository and run the example application following the instructions in the README.