PoiQuery Class

Once POIs have been generated, either by Naurt or yourself, you'll be able to query them using powerful location and information based filters.

Import

Kotlin
import com.naurt.sdk.poi.PoiQuery
import com.naurt.sdk.poi.PoiQuery.Builder

Constructor

The PoiQuery class cannot be directly made with it's constructor. You must build the class via it's Builder. There are three ways to query POI data - with a valid latitude and longitude and/or with the metadata search and then a direct look up by POI ID.

Kotlin

class Builder(
    apiKey: String,
    poiTypes: List<String>,
    latitude: Double,
    longitude: Double
)

class Builder(
    apiKey: String,
    poiTypes: List<String>,
    metadata: JSONObject
)

class Builder(
    apiKey: String,
    poiID: String
)

When building a query based around a location, the response will return the closest POIs. When building a query around metadata, the most recently created POIs with an exact match will be returned. For more information please visit the POI API documentation. The following example would return the closest 25 restaurants to 10.0 degrees longitude 10.0 degrees latitude that you have inserted into the POI system.

Kotlin
val poiQuery = PoiQuery.Builder(
    "API_KEY_HERE",
    listOf("restaurant"),
    10.0,
    10.0,
).build()

You could then build on this by querying the closest italian restaurants.

Kotlin
val poiQuery = PoiQuery.Builder(
    BuildConfig.API_KEY,
    listOf("restaurant"),
    JSONObject(mapOf("type" to "italian"))
).setDistanceFilter(1e10, 10.23423, 10.23123).build()

This class conforms to the POI API specification and more details on how to build different queries can be found on the page.

Once built, the request to query the POI can be carried out using the .send() method.


send

This method runs a web request and triggers a callback, so ensure it is correctly spawned off to avoid blocking the main thread.

Signature

poiQuery.send(callback: PoiCallback<JSONObject>)

Parameters

  • callback: A Naurt PoiCallback which will receive the result of the web request. If successful a JSON response will be available. If unsuccessful a status code and a JSON containing the error will be present.

Returns

None, but will trigger the callback once the request is done.

Throws

Does not throw.