Skip to main content
GuidesAPI ReferenceExamples

Overlapped Maps

|

This example demonstrates how to create an Android application that display overlapped maps, showcasing the ability to layer map views.

Two overlapped Map Views

UI and Map Integration

The main application consists of a simple user interface that displays two maps stacked on top of each other. The user can see both maps simultaneously, allowing for comparison or overlaying of different data.

MainActivity overrides the onCreate() function, which calls the findViewById() function to find the surface on which the default map is rendered.

After the default map is created, the overlapped map is created as shown in the code block gemSurfaceView.onDefaultMapViewCreated = { ... }.

MainActivity.kt
class MainActivity : AppCompatActivity() {
private lateinit var gemSurfaceView: GemSurfaceView
private var secondMapView: MapView? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

// Add the small overlapped map
gemSurfaceView = findViewById(R.id.gem_surface)
gemSurfaceView.onDefaultMapViewCreated = {
gemSurfaceView.gemScreen?.let { screen ->
val secondViewRect = RectF(0.0f, 0.0f, 0.5f, 0.5f)
secondMapView = MapView.produce(screen, secondViewRect, null, true)
}
}
...
}
override fun onDestroy() {
super.onDestroy()

// Deinitialize the SDK.
GemSdk.release()
}
}

A short message will be shown on screen if the API Token is rejected using SdkSettings.onApiTokenRejected.