> For the complete documentation index, see [llms.txt](https://docs.mapbox.com/android/ja/java/llms.txt)

# Tilequery

This guide provides an overview of how to query Mapbox-hosted **vector tile features** near a point using the Mapbox Java SDK.

The [Mapbox Tilequery API](https://docs.mapbox.com/api/maps/tilequery/) allows you to retrieve data about specific features from a vector tileset, based on a given latitude and longitude. The API makes it possible to query for features within a radius, do point in polygon queries, query for features in multiple composite layers, and augment data from the Mapbox Geocoding API with custom data.

For more information about this API, including its pricing structure, see the [Mapbox Tilequery API documentation](https://docs.mapbox.com/api/maps/tilequery/).

## Import packages

```java
import com.mapbox.api.tilequery.MapboxTilequery
import com.mapbox.geojson.FeatureCollection
```

## Building the query URL

To begin with, you'll need to create a new instance of the `MapboxTilequery` object and use its builder to customize your query. The options offered in the builder includes choices such as the query coordinate, the type of GeoJSON geometry you're searching for, and the search area radius.

**Java**

```java
MapboxTilequery tilequery = MapboxTilequery.builder()
	.accessToken(MAPBOX_ACCESS_TOKEN)
	.tilesetIds(tilesetId)
	.query(Point.fromLngLat(LONGITUDE,LATITUDE))
	.radius(radiusInMeters)
	.limit(maxNumOfFeaturesReturned)
	.geometry(geoJsonGeometryString) // "point", "linestring", or "polygon"
	.dedupe(boolean)
	.layers(singleOrListOfMapLayerIds) // layer name within a tileset, not a style
	.build();
```

**Kotlin**

```kt
val tilequery = MapboxTilequery.builder()
	.accessToken(MAPBOX_ACCESS_TOKEN)
	.tilesetIds(tilesetId)
	.query(Point.fromLngLat(LONGITUDE,LATITUDE))
	.radius(radiusInMeters)
	.limit(maxNumOfFeaturesReturned)
	.geometry(geoJsonGeometryString) // "point", "linestring", or "polygon"
	.dedupe(boolean)
	.layers(singleOrListOfMapLayerIds) // layer name within a tileset, not a style
	.build()
```

> **Related content (playground): [Tilequery Playground](https://docs.mapbox.com/playground/tilequery/)**
> 
> Create and run Tilequery API queries and see the results on a map.

## Query response

Access the [Tilequery API response object](https://docs.mapbox.com/api/maps/#response-retrieve-features-from-vector-tiles) inside the `onResponse` callback. The `onResponse` callback is built with [Retrofit](https://www.geeksforgeeks.org/android/introduction-retofit-2-android-set-1/), like the Java SDK's other services' callbacks. The response will include a `List<Feature>` if the query you built has any `Feature`s in it. But, there's no guarantee that the response will have any `Feature` objects in it.

**Java**

```java
tilequery.enqueueCall(new Callback<FeatureCollection>() {
	@Override public void onResponse(Call<FeatureCollection> call, Response<FeatureCollection> response) {

		List<Feature> featureList = response.body().features();

	}

	@Override public void onFailure(Call<FeatureCollection> call, Throwable throwable) {

		Log.d("Request failed: %s", throwable.getMessage());

	}
});
```

**Kotlin**

```kt
tilequery.enqueueCall(object : Callback<FeatureCollection> {
	override fun onResponse(call: Call<FeatureCollection>, response: Response<FeatureCollection>) {

		val featureList = response.body()?.features()

	}

	override fun onFailure(call: Call<FeatureCollection>, throwable: Throwable){

		Log.d(TAG, "Request failed: %s", throwable.message)

	}
})
```

Each `Feature` in the response has a `distance`, `geometry`, and `layer` property associated with it:

**Java**

```java
tilequery.enqueueCall(new Callback<FeatureCollection>() {
	@Override public void onResponse(Call<FeatureCollection> call, Response<FeatureCollection> response) {

		// The FeatureCollection that is inside the API response

		List<Feature> featureList = response.body().features();

		// Distance that the Feature is from the original Tilequery Point coordinate
		String distance = featureList.get(0).getProperty("tilequery").getAsJsonObject().get("distance").toString();

		// The Feature's GeoJSON geometry type     
        String geometryType = featureList.get(0).getProperty("tilequery").getAsJsonObject().get("geometry").toString();

        // The id of the map layer which the Feature is a part of        
        String layerId = featureList.get(0).getProperty("tilequery").getAsJsonObject().get("layer").toString();
	}

	@Override public void onFailure(Call<FeatureCollection> call, Throwable throwable) {

		Log.d("Request failed: %s", throwable.getMessage());

	}
});
```

**Kotlin**

```kt
tilequery.enqueueCall(object : Callback<FeatureCollection> {
	override fun onResponse(call: Call<FeatureCollection>, response: Response<FeatureCollection>) {

		// The FeatureCollection that is inside the API response

		val featureList.get = response.body()?.features()

		// Distance that the Feature is from the original Tilequery Point coordinate

		val distance = featureList[0].getProperty("tilequery").asJsonObject.get("distance").toString()

    // The Feature's GeoJSON geometry type
    val geometryType = featureList[0].getProperty("tilequery").asJsonObject.get("geometry").toString()

    // The id of the map layer which the Feature is a part of
    val layerId = featureList[0].getProperty("tilequery").asJsonObject.get("layer").toString()()

	}

	override fun onFailure(call: Call<FeatureCollection>, throwable: Throwable){

		Log.d(TAG, "Request failed: %s", throwable.message)

	}
})
```