Search (v2.1.x - Android)
In Navmii SDK it is possible to search addresses and places. You can get a SearchManager
instance via getSearchManager
method in the Sdk
singleton. SearchManager
exposes several builders to create the objects needed to perform all possible lookups in the SDK.
SearchManager searchManager = sdk.getSearchManager();
All the classes used for search in the SDK inherit from the Request
abstract class. So, all available requests have the following parameters:
search location
maximum number of search results
locale
These parameters can be set via setSearchLocation
, setMaxResultCount
and setLocale
methods of each Request
's builder. There is also Request.getStatus
method, that allows to get the request's current status represented as RequestStatus
enum:
NONE
PROCEEDING
SUCCESS
CANCELED
FAILED
Request
has method start
which takes the CompletionListener
as an argument, allowing you to pass a listener, which will handle the search results if the request succeeds, or an error in case of failure. You also can cancel the request with the cancel
method.
Country and State Search
The fastest and the most lightweight request is CountryAndStateRequest
. Use this request instead of the ReverseGeocodingRequest
when you want to know only country and state at some coordinates. You can create a builder for this request with the SearchManager.createCountryAndStateRequest
method. When you perform this search, a List<Place>
containing a single item will be returned to the listener.
Request countryStateRequest =
searchManager.createCountryAndStateRequest(coordinates).build();
countryStateRequest.start(new Request.CompletionListener() {
@Override
public void onRequestCompleted(Request request, List<Place> results) {
Address countryAndState = results.get(0).getAddress();
Log.i("CountryAndStateRequest",
String.format(
"Request completed: %s %s",
countryAndState.getCountry(),
countryAndState.getState()));
}
@Override
public void onRequestFailed(Request request, RequestError error) {
Log.i("CountryAndStateRequest", "Request failed: " + error);
}
});
Reverse Geocoding Search
If you want to get the address at some coordinates use ReverseGeocodingRequest
. To create a builder for this request use the SearchManager.createReverseGeocodingRequest
method.
Request reverseGeocodingRequest =
searchManager.createReverseGeocodingRequest(coordinates).build();
reverseGeocodingRequest.start(new Request.CompletionListener() {
@Override
public void onRequestCompleted(Request request, List<Place> results) {
Log.i("ReverseGeocodingRequest", "Request completed:");
for (Place place : results) {
Log.i("ReverseGeocodingRequest", place.toString());
}
}
@Override
public void onRequestFailed(Request request, RequestError error) {
Log.i("ReverseGeocodingRequest", "Request failed: " + error);
}
});
Note: if only country and state are relevant for your search please refer to Country and State Search.
POI Search
You can perform search for Places of Interest (POIs) located within a search radius from some coordinates and containing a specified text string in their names. In order to do this use a PoiRequest
instance created via the SearchManager.createPoiRequest
. By default, the search is performed within the radius of 100 meters and among all POI categories. You can specify these parameters with setSearchRadius
and setPoiCategories
methods of the request's builder. Search results in the returned array will be sorted by distance (from closer to farther) from the search location.
Specifying POI categories
It’s also possible to include only specific POI categories into search results by using PoiRequest.Builder.setCategories()
method.
Please refer to this page for the list of category identifiers.
Geocoding Search
You also can get coordinates for a String
representing a particular address. In order to do this use a GeocodingRequest
instance, which can be created using the SearchManager.createGeocodingRequest
method.