Location Wikipedia
In this guide you will learn how to render an interactively defined road block on an interactive map, and fly to the road block.
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 LocationWikipedia 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.


How it works
You can open the MainActivity.kt file to see how the wikipedia page is obtained and displayed.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
locationName = findViewById(R.id.locationName)
locationWiki = findViewById(R.id.locationWiki)
progressBar = findViewById(R.id.progressBar)
SdkSettings.onMapDataReady = onMapDataReady@{ isReady ->
if (!isReady) return@onMapDataReady
search()
}
SdkSettings.onApiTokenRejected = {
// Check the TOKEN provided in the AndroidManifest.xml file.
showToast("TOKEN REJECTED")
}
// This step of initialization is mandatory if you want
// to use the SDK without a map.
if (!GemSdk.initSdkWithDefaults(this)) {
finish()
}
if (!Util.isInternetConnected(this)) {
Toast.makeText(this, "You must be connected to internet!",
Toast.LENGTH_LONG).show()
}
}
The MainActivity
overrides the onCreate
function, which checks that the API token is valid, initializes the maps SDK, and checks that internet access is available.
As soon as the map is ready, the search()
function is called automatically.
private fun search() = SdkCall.execute {
val name = "Eiffel Tower"
val coordinates = Coordinates(0.0, 0.0)
searchService.searchByFilter(name, coordinates)
}
The text string containing the name to search for is set in the search()
function, and searchService.searchByFilter
is called.
Coordinates are not necessary and can be set to 0.
private val searchService = SearchService(
onStarted = {
progressBar?.visibility = View.VISIBLE
},
onCompleted = { results, errorCode, _ ->
progressBar?.visibility = View.GONE
if (errorCode == GemError.NoError) {
if (results.isNotEmpty()) {
val name = SdkCall.execute { results[0].name }
locationName?.text = name
requestWiki(results[0])
} else {
// The search completed without errors,
// but there were no results found.
showToast("No results!")
}
}
}
)
When the search completes, the first result (at index 0) is passed to requestWiki(results[0])
to load the wikipedia page, unless the search found no results, in which case a message to that effect is displayed instead: showToast("No results!")
Android Examples
Maps SDK for Android Examples can be downloaded or cloned with Git.