MapSDK - Getting started
Installation
Before you start developing your application with WemapSDKs, you 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 WemapMapSDK library for Android:dependencies {
// Add the dependency for the WemapMapSDK library
implementation "com.getwemap.sdk:map:<version>"
}Ensure that your project's minSdkVersion is set to API 21 or higher:
android {
...
defaultConfig {
minSdkVersion 21
}
}Since you've modified your Gradle files, Android Studio will prompt you to sync the Gradle files. Proceed with syncing.
Add a map
Open the activity where you want to add a map and use the following code.
To make it work, you need to provide mapID
and token
in 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 io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import org.maplibre.android.MapLibre
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
val mapView get() = binding.mapView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
MapLibre.getInstance(applicationContext)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
val request = WemapMapSDK.instance
.mapData(19158, "GUHTU6TYAWWQHUSR5Z5JZNMXX") // Specify your mapID and token here
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
mapView.mapData = it
}, {
println("Failed to get map data with error - ${it.message}")
})
}
}
Modify the Activity’s XML Layout
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
manages Android’s OpenGL lifecycle. To ensure proper lifecycle management, override the following methods in the Activity
that contains the WemapMapView
. If you are using a Fragment
, call mapView.onDestroy()
inside the fragment’s onDestroyView()
method instead of 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
For additional examples and sample implementations of WemapSDKs, visit the official GitHub repository.
Clone the repository and follow the README instructions to run the sample application.