Skip to content Skip to sidebar Skip to footer

How To Get A List Of Addresses By A Search Without The Map?

I'm trying to get a list of addresses by searching an address in an editText, using Google Maps API. For example, if I'm searching for an address in the editText at the top of the

Solution 1:

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

  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"
    />
    
  2. Use PlaceSelectionListener:

    PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
    getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
    
    autocompleteFragment.setOnPlaceSelectedListener(newPlaceSelectionListener() {
    @OverridepublicvoidonPlaceSelected(Place place) {
        // TODO: Get info about the selected place.Log.i(TAG, "Place: " + place.getName());
    }
    
    @OverridepublicvoidonError(Status status) {
        // TODO: Handle the error.Log.i(TAG, "An error occurred: " + status);
    }
    });
    

    Note from the documentation:

    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.

Solution 2:

First you need a component, something like AutoCompleteTextView.

Second Google has a documentations about autosuggestion address. It is so simple, register, create an api key and so on. Here is a link to doc.

Logic: User press type a text, component fired a callback onTextChanged and you make a request to get suggestion list, after show a received list to user.

Post a Comment for "How To Get A List Of Addresses By A Search Without The Map?"