Skip to main content

Place picker

Not compatible with the Maps SDK v10
This plugin is not compatible with the Maps SDK v10 or higher. To add search functionality to an application using the Maps SDK v10 and higher, see the Search SDK for Android documentation.

This example uses the Places plugin to use Mapbox's location search capabilities. The plugin automatically makes geocoding requests, has built-in saved locations, includes location picker functionality, and adds a beautiful search UI into your Android project.

You must install the plugin before running the application.


This example is a part of the Mapbox Android Demo app. You can find the values for all referenced resources in the res directory. For example, see res/values/activity_strings.xml for R.string.* references used in this example.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android=""

android:text="@string/go_to_picker_activity" />

android:layout_height="match_parent" />

package com.mapbox.mapboxandroiddemo.examples.plugins;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.mapbox.api.geocoding.v5.models.CarmenFeature;
import com.mapbox.mapboxandroiddemo.R;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.plugins.places.picker.PlacePicker;
import com.mapbox.mapboxsdk.plugins.places.picker.model.PlacePickerOptions;

* Use the place picker functionality inside of the Places Plugin, to show UI for
* choosing a map location. Once selected, return to the previous location with a
* CarmenFeature to extract information from for whatever use that you want.
public class PlaceSelectionPluginActivity extends AppCompatActivity {

private static final int REQUEST_CODE = 5678;
private TextView selectedLocationTextView;

protected void onCreate(Bundle savedInstanceState) {

// Mapbox access token is configured here. This needs to be called either in your application
// object or in the same activity which contains the mapview.
Mapbox.getInstance(this, getString(R.string.access_token));

// This contains the MapView in XML and needs to be called after the access token is configured.

selectedLocationTextView = findViewById(;

* Set up the PlacePickerOptions and startActivityForResult
private void goToPickerActivity() {
new PlacePicker.IntentBuilder()
.statingCameraPosition(new CameraPosition.Builder()
.target(new LatLng(40.7544, -73.9862)).zoom(16).build())
.build(this), REQUEST_CODE);

* This fires after a location is selected in the Places Plugin's PlacePickerActivity.
* @param requestCode code that is a part of the return to this activity
* @param resultCode code that is a part of the return to this activity
* @param data the data that is a part of the return to this activity
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_CANCELED) {
// Show the button and set the OnClickListener()
Button goToPickerActivityButton = findViewById(;
goToPickerActivityButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
} else if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
// Retrieve the information from the selected location's CarmenFeature
CarmenFeature carmenFeature = PlacePicker.getPlace(data);

// Set the TextView text to the entire CarmenFeature. The CarmenFeature
// also be parsed through to grab and display certain information such as
// its placeName, text, or coordinates.
if (carmenFeature != null) {
getString(R.string.selected_place_info), carmenFeature.toJson()));
Was this example helpful?