Skip to main content

MapSDK - Getting started

The WemapMapSDK is a library for embedding customized interactive maps within mobile applications.

Requirements

Check common requirement.

Installation

Check common installation.

Add a map

At first add WemapMapView to your layout:

<com.getwemap.sdk.map.WemapMapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

Once you have the MapData, assign MapData to the WemapMapView as follows:

mapView.mapData = mapData

Wait MapView to load

You must wait until WemapMapView finishes loading view getMapViewAsync, because only when this method is called, it's safe to access WemapMapView properties.

mapView.getMapViewAsync { mapView, map, style, mapData ->
// now it's safe to access MapView properties
}

MapView lifecycle

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

User Location

Wemap provides various location sources to track the user's location on the map. For more info check positioning docs

By default, WemapMapSDK uses Android GPS and Network Providers. But you can easily take any WemapPositioningSDK create LocationSource and connect it to the WemapMapView as shown below:

fun setupLocationSource(mapData: MapData) {
val locationSource = AndroidFusedAdaptiveLocationSource(requireContext(), mapData) // it can be any LocationSource from WemapPositioningSDK
mapView.locationManager.locationSource = locationSource
}

The full example is available in our GitHub repository.

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.