GPX Import
In this guide you will learn how to load a GPX route and render it on the map.
Setup
- Get your Magic Lane API key token: if you do not have a token, see the Getting Started guide
- Download the Maps & Navigation SDK for Android archive file
- Download the GPXImport 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
An android device should be connected via USB cable.
Press SHIFT+F10 to compile, install and run the example on the android device.

A GPX route is loaded and rendered on the map.
How it works
You can open the MainActivity.kt file to see how the GPX route is imported and rendered on the map.
In the class MainActivity:AppCompatActivity()
, an instance of val routingService = RoutingService()
is created.
The override fun onCreate()
calls the calculateRouteFromGPX()
function after the map is loaded.
private fun calculateRouteFromGPX() = SdkCall.execute {
val gpxAssetsFilename = "gpx/test_route.gpx"
// Opens GPX input stream.
val input = applicationContext.resources.assets.open(gpxAssetsFilename)
// Produce a Path based on the data in the buffer.
val track = Path.produceWithGpx(input/*.readBytes()*/) ?: return@execute
val mapView = gemSurfaceView.mapView ?: return@execute
// Set the line color to red and display the path on the map.
val lineColor = Rgba.red()
mapView.presentPath(track, lineColor, lineColor)
// Set the transport mode to bike and calculate the route.
routingService.calculateRoute(track, ERouteTransportMode.Bicycle)
}
This function defines the name of the GPX route file name as "gpx/test_route.gpx"
which is found in the assets/
directory of this example.
Next, the file is opened, and a route is generated from the GPX data.
track = Path.produceWithGpx(input)
Then the mapView
is obtained
val mapView = gemSurfaceView.mapView
and the route color is set to red.
val lineColor = Rgba.red()
The route is passed to the mapView,
mapView.presentPath(track, lineColor, lineColor)
and then the routing service is used to calculate the route for bicycles.
routingService.calculateRoute(track, ERouteTransportMode.Bicycle)
In this example, the routingService
is used only to compute the route; no navigation is simulated.
Android Examples
Maps SDK for Android Examples can be downloaded or cloned with Git