Search Nearby
In this guide you will learn how to search for points of interest (POIs) near the current location.
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 WhatsNearby 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 text list of results is shown of various points of interest near the current location of the device.
How it works
You can open the MainActivity.kt file to see how to search for POIs near the current or a specified location.
private fun search()
{
// If one of the location permissions is granted, we can do the search around action.
val hasPermissions =
PermissionsHelper.hasPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
if (hasPermissions)
{
Util.getMyPosition()?.let { myPosition ->
searchAround(myPosition)
}
}
}
private fun searchAround(reference: Coordinates)
{
SdkCall.execute
{
// Cancel any search that is in progress now.
cancelSearch()
// Set the necessary preferences.
searchService.preferences.setSearchAddresses(true)
searchService.preferences.setSearchMapPOIs(true)
// Search around position using the provided search preferences and/ or filter.
searchService.searchAroundPosition(
reference, ""
)
}
}
If location permission was given by the user, then the search()
function can call the searchAround()
function, which sets the preferences to search for POIs and addresses.
Then it starts the search with the API function searchService.searchAroundPosition()
and when the search completes, the searchService.onCompleted
callback function is invoked to put the results in a list for display:
when (val gemError = SdkError.fromInt(reason))
{
SdkError.NoError ->
{
// No error encountered, we can handle the results.
val reference = Util.getMyPosition() ?: return@onCompleted
val adapter = CustomAdapter(reference, results)
listView?.adapter = adapter
if (results.isEmpty())
{
// The search completed without errors, but there were no results found.
}
}
Android Examples
Maps SDK for Android Examples can be downloaded or cloned with Git.