What's Nearby Category
In this guide you will learn how to search for points of interest (POIs) near the current location looking for a certain type of POIs, like gas stations.
A searchService = SearchService()
is instantiated to carry out searching for selected category's POIs around the current actual or simulated position of the device. The onCompleted
listener is defined, which is invoked when the search completes and checks if there was no error and that the results are not empty. When successful, it passes the non-empty result list to the CustomAdapter
to be displayed in a scrollable list of nearby POIs.
MainActivity
overrides the onCreate
function, which checks that internet access is available, initializes the SDK, and requests location permission from the user. When the map is ready (loaded and initialized), it automatically invokes the search.
If location permission was given by the user, then the search()
function can call the searchAround()
function, which cancels the ongoing search in progress, if any, and then starts a search for gas station POIs: searchService.searchAroundPosition(EGenericCategoriesIDs.GasStation)
.
When no category is selected, the example searches for the closest POIs based on the user actual or simulated location.
When the search completes, the searchService.onCompleted
listener callback function, defined in the searchService
, is invoked to put the results in a scrollable list for display, using a CustomAdapter
: