Подтвердить что ты не робот

Добавить панель инструментов поиска по карте google, например, в приложении для родных Android.

Я хочу реализовать панель инструментов поиска, например, в приложении Google Maps. Как я могу это сделать? Может быть, есть собственный способ реализовать эту функцию?

snapshot from google maps app

4b9b3361

Ответ 1

Вам следует использовать AutoSuggestEditext и давать фоновый эффект, например google, и поставить левое и правое изображение на Relativelayout

Вот пример для автоматического поиска для поиска по месту.

Автозаполнение завершено

Надеюсь на это вы поймете.

Ответ 2

Вы можете использовать EditText или TextWatcher. Я использовал кнопку EditText и кнопку поиска. С помощью этого щелчка на кнопке найдите местоположение.

Вот мой код при нажатии кнопки:

button1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            String g = searchview.getText().toString();

            Geocoder geocoder = new Geocoder(getBaseContext());
            List<Address> addresses = null;

            try {
                // Getting a maximum of 3 Address that matches the input
                // text
                addresses = geocoder.getFromLocationName(g, 3);
                if (addresses != null && !addresses.equals(""))
                    search(addresses);

            } catch (Exception e) {

            }

        }
    });

и вот метод поиска

protected void search(List<Address> addresses) {

    Address address = (Address) addresses.get(0);
    home_long = address.getLongitude();
    home_lat = address.getLatitude();
    latLng = new LatLng(address.getLatitude(), address.getLongitude());

    addressText = String.format(
            "%s, %s",
            address.getMaxAddressLineIndex() > 0 ? address
                    .getAddressLine(0) : "", address.getCountryName());

    markerOptions = new MarkerOptions();

    markerOptions.position(latLng);
    markerOptions.title(addressText);

    map1.clear();
    map1.addMarker(markerOptions);
    map1.moveCamera(CameraUpdateFactory.newLatLng(latLng));
    map1.animateCamera(CameraUpdateFactory.zoomTo(15));
    locationTv.setText("Latitude:" + address.getLatitude() + ", Longitude:"
            + address.getLongitude());


}

Отредактировано для xml-кода

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.google_map.MainActivity" >

 <fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    class="com.google.android.gms.maps.SupportMapFragment" />

<TextView
    android:id="@+id/latlongLocation"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignRight="@+id/searchView1"
    android:background="#ff058fff"
    android:gravity="bottom"
    android:paddingBottom="5dp"
    android:paddingLeft="5dp"
    android:paddingRight="5dp"
    android:paddingTop="5dp"
    android:textColor="#ffffffff" />

<EditText
    android:id="@+id/searchView1"
    android:layout_width="250dp"
    android:layout_height="34dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="18dp"
    android:layout_marginTop="14dp"
    android:hint="Search Location"
    android:textColor="@android:color/black"
    android:background="@android:color/white" >
</EditText>

<Button
    android:id="@+id/button1"
    android:layout_width="28dp"
    android:layout_height="25dp"
    android:layout_alignBaseline="@+id/searchView1"
    android:layout_alignBottom="@+id/searchView1"
    android:layout_alignRight="@+id/searchView1"
    android:background="@drawable/g_search_btn" /></RelativeLayout>

Ответ 3

Если вы хотите получить представление "Поиск по карте Google". Затем вы можете использовать любую из двух нижележащих удивительных библиотек.

1) Плавающий вид поиска

Добавьте ниже зависимости от вашего файла gradle:

compile 'com.github.arimorty:floatingsearchview:2.0.3'

Пример:

   <com.arlib.floatingsearchview.FloatingSearchView
            android:id="@+id/floating_search_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:floatingSearch_searchBarMarginLeft="@dimen/search_view_inset"
            app:floatingSearch_searchBarMarginTop="@dimen/search_view_inset"
            app:floatingSearch_searchBarMarginRight="@dimen/search_view_inset"
            app:floatingSearch_searchHint="Search..."
            app:floatingSearch_suggestionsListAnimDuration="250"
            app:floatingSearch_showSearchKey="false"
            app:floatingSearch_leftActionMode="showHamburger"
            app:floatingSearch_menu="@menu/menu_main"
            app:floatingSearch_close_search_on_keyboard_dismiss="true"/>

2) SearchView

Добавьте ниже зависимости от вашего файла gradle:

compile 'com.lapism:searchview:4.0'

Пример:

<com.lapism.searchview.SearchView
    android:id="@+id/searchView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

Ответ 4

Это может помочь кому-то, кто хочет добавить панель поиска вместе с картами Google API Google Адресов