Fly To Coordinates ¶
Setup ¶
First, get an API key token, see the Getting Started guide.
Download the Maps & Navigation SDK for Android archive file
Download the
FlyToCoordinates
project
archive file or clone the project with Git
See the Configure Android Example guide.
Run the example ¶
In Android Studio, from the
File
menu, select
Sync
Project
with
Gradle
Files
|
|||
How it works ¶

You can open the MainActivity.kt file and edit the coordinates of the destination (latitude, longitude) as shown in the code below, and run the app again to fly to a different destination.
1override fun onCreate(savedInstanceState: Bundle?) {
2 super.onCreate(savedInstanceState)
3 setContentView(R.layout.activity_main)
4 gemSurfaceView = findViewById(R.id.gem_surface)
5 SdkSettings.onMapDataReady = onMapDataReady@{ isReady ->
6 if (!isReady) return@onMapDataReady
7 SdkCall.execute {
8 // Defines an action that should be done after the world map is ready.
9 flyTo(Coordinates(2.33412, 48.86144)) //pyramide inversee, Louvre, Paris
10 }
11 }
12 if (!Util.isInternetConnected(this)) {
13 Toast.makeText(this, "You must be connected to internet!",
14 Toast.LENGTH_LONG).show()
15 }
16}
MainActivity
overrides the
onCreate()
function which checks
that internet access is available,
and then, when the map is initialized and ready, flies the camera to
the specified hardcoded coordinates.
1private fun flyTo(coordinates: Coordinates) = SdkCall.execute {
2 // Center the map on a specific set of coordinates using the provided animation.
3 gemSurfaceView.mapView?.centerOnCoordinates(coordinates)
4}
flyTo()
function is implemented using
gemSurfaceView.mapView?.centerOnCoordinates(coordinates)
,
where the coordinates are given as longitude, latitude in degrees.
Coordinates
to (45.43597, 12.33060)
to fly to Venice instead of Louvre, and then run the example again.