Place Picker

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.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) {
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.
getString(R.string.selected_place_info), carmenFeature.toJson()));
Was this page helpful?