Skip to main content

Map+PositioningSDK - 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.

info

The code examples below demonstrate how to configure the WemapPositioningSDK to work with the WemapMapSDK, but it can also be used independently. Instructions are here

Add the dependency

Add the WemapSDKs to your app

  1. In your module-level Gradle file (usually project/module/build.gradle.kts or project/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>"

    // Add the dependency for the WemapPositioningSDK library
    implementation "com.getwemap.sdk.positioning:fused-gms:<version>" // Google's Fused Location Source
    implementation "com.getwemap.sdk.positioning:polestar:<version>" // Polestar Location Source
    implementation "com.getwemap.sdk.positioning:wemap-vps-arcore:<version>" // Wemap VPS ARCore Location Source
    }
  2. Ensure that your project's minSdkVersion is set to API 21 or higher:

    android {
    ...
    defaultConfig {
    minSdkVersion 21
    }
    }
  3. Since you've modified your Gradle files, Android Studio will prompt you to sync the Gradle files. Proceed with syncing.

Location Sources

Wemap provides a variety of location sources to manage the user’s location on the map. By default, WemapMapSDK uses Android GPS and Network Providers to obtain raw location updates.

To set a specific location source, you need to:

  • Add the relevant WemapPositioningSDK library to your project dependencies.

  • Assign the location source to the map.

info

If you want the camera to follow the user’s direction, you can do so by changing renderMode and cameraMode of locationManager, as shown below:

mapView.locationManager.apply {
cameraMode = CameraMode.TRACKING_COMPASS
renderMode = RenderMode.COMPASS
}

Google's Fused location source

fun setupLocationSource() {
mapView.locationManager.apply {
source = GmsFusedLocationSource(applicationContext)
isEnabled = true
}
}

Polestar location source

fun setupLocationSource() {
mapView.locationManager.apply {
source = PolestarLocationSource(applicationContext, "emulator") // change 'emulator' to your polestar API key here
isEnabled = true
}
}

Wemap VPS ARCore location source

To use the VPS Location Source, you must have a mapID and token or a VPS serviceURL. For more details, please contact Wemap team.

Fetching the VPS Service URL

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}")
})

Setting Up the VPS ARCore Location Source

Once you have the serviceURL, create a WemapVPSARCoreLocationSource instance:

fun setupLocationSource() {
val vpsLocationSource = WemapVPSARCoreLocationSource(requireContext(), mapData.extras?.vpsEndpoint ?: "https://your-wemap-vps-endpoint")
vpsLocationSource.bind(requireContext(), surfaceView)
vpsLocationSource.vpsListeners.add(vpsListener)

mapView.locationManager.apply {
source = vpsLocationSource
isEnabled = true
}
}

Handling Location Source State Changes

You must handle state changes in WemapVPSARCoreLocationSourceListener, as users may need to scan their environment.

private val vpsListener by lazy {
object : WemapVPSARCoreLocationSourceListener {

override fun onStateChanged(state: WemapVPSARCoreLocationSource.State) {
// Handle state changes
}

override fun onScanStatusChanged(status: WemapVPSARCoreLocationSource.ScanStatus) {
// Handle scan status changes
}

override fun onError(error: WemapVPSARCoreLocationSourceError) {
// Handle location source errors
}
}
}

Scanning the Environment

To start tracking the user's location, you need to allow the user to scan their environment:

fun startScan() {
vpsLocationSource.startScan()
}

Once the system successfully recognizes the user's location, it will report the ACCURATE_POSITIONING state to WemapVPSARCoreLocationSourceListener. Shortly after, VPS system will start updating user's location indicator on the map.

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.