Reputation: 534
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 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.
Upvotes: 2
Views: 1259
Reputation: 7661
There is the option of using the PlaceAutocompleteFragment
- when I first added it, I had no billing account so you should be good:
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"
/>
Use 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:
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 theSupportPlaceAutocompleteFragment
class. You must also include the Android v4 Support Library.
Upvotes: 1
Reputation: 1310
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.
Upvotes: 0