如何在没有地图的情况下通过搜索获取​​地址列表? [英] How to get a list of addresses by a search without the map?

查看:89
本文介绍了如何在没有地图的情况下通过搜索获取​​地址列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过使用Google Maps API在editText中搜索地址来获取地址列表.

I'm trying to get a list of addresses by searching an address in an editText, using Google Maps API.

例如,如果我要在屏幕顶部的editText中搜索地址,则该地址下方将显示一个可供选择的地址列表.

For example, if I'm searching for an address in the editText at the top of the screen, below it, there will be a list of addresses that you can choose.

我不需要地图的一部分,只需要结果和搜索框.

I don't need the map part of it, just the results, and the search box.

推荐答案

可以选择使用PlaceAutocompleteFragment-当我第一次添加它时,我没有计费帐户,因此您应该会很好:

There is the option of using the PlaceAutocompleteFragment - when I first added it, I had no billing account so you should be good:

  1. 将其添加到XML

  1. Add it on the XML

<fragment
android:id="@+id/place_autocomplete_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
/>

  • 使用PlaceSelectionListener:

    PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
    getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
    
    autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
    @Override
    public void onPlaceSelected(Place place) {
        // TODO: Get info about the selected place.
        Log.i(TAG, "Place: " + place.getName());
    }
    
    @Override
    public void onError(Status status) {
        // TODO: Handle the error.
        Log.i(TAG, "An error occurred: " + status);
    }
    });
    

    文档 中的注释:

    Note from the documentation:

    Google Places API需要API级别12或更高级别才能支持PlaceAutocompleteFragment对象.如果您要定位API级别12之前的应用程序,则可以通过SupportPlaceAutocompleteFragment类访问相同的功能.您还必须包括Android v4支持库.

    The Google Places API requires API level 12 or higher for the support of PlaceAutocompleteFragment objects. If you are targeting an application earlier than API level 12, you can access the same functionality through the SupportPlaceAutocompleteFragment class. You must also include the Android v4 Support Library.

  • 这篇关于如何在没有地图的情况下通过搜索获取​​地址列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆