I have a map activity with a MapBox map, and I want to show in the top part of the screen a search bar to search places. I've included the following libraries in my app gradle:
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:7.2.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v7:0.5.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-places-v7:0.7.0'
The layout xml file looks like following:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="it.quintetto.seeme.ui.maps.MapsActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_profileview2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/black"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.ConstraintLayout
android:id="@+id/mapSearchBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="30dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar_profileview2"/>
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/mapSearchBar"
app:layout_constraintBottom_toBottomOf="parent"
app:mapbox_cameraTargetLat="40.73581"
app:mapbox_cameraTargetLng="-73.99155"
app:mapbox_cameraZoom="11" />
</android.support.constraint.ConstraintLayout>
The content of the activity is:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Mapbox.getInstance(this, <token>);
setContentView(R.layout.activity_maps);
mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mapboxMap.setStyle(Style.MAPBOX_STREETS, new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded(@NonNull Style style) {}
});
}
});
PlaceAutocompleteFragment autocompleteFragment;
if (savedInstanceState == null) {
autocompleteFragment = PlaceAutocompleteFragment.newInstance(<token>);
final FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(R.id.mapSearchBar, autocompleteFragment, PlaceAutocompleteFragment.TAG);
transaction.commit();
} else {
autocompleteFragment = (PlaceAutocompleteFragment)getSupportFragmentManager().findFragmentByTag(PlaceAutocompleteFragment.TAG);
}
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(CarmenFeature carmenFeature) {
Toast.makeText(MapsActivity.this,
carmenFeature.text(), Toast.LENGTH_LONG).show();
finish();
}
@Override
public void onCancel() {
finish();
}
});
}
@Override
public void onStart() {
super.onStart();
mapView.onStart();
}
@Override
public void onResume() {
super.onResume();
mapView.onResume();
}
@Override
public void onPause() {
super.onPause();
mapView.onPause();
}
@Override
public void onStop() {
super.onStop();
mapView.onStop();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
When I open the activity, the map shows up and also the virtual keyboard appears, with a lens instead of the usual enter button. But there is no search bar. How can I solve?
Thanks