Class PlacesAutocomplete

java.lang.Object
com.codename1.ui.Component
com.codename1.ui.Container
com.codename1.maps.places.PlacesAutocomplete
All Implemented Interfaces:
Animation, Editable, StyleListener, Iterable<Component>

public class PlacesAutocomplete extends Container

A search field that suggests places as the user types and resolves the chosen one to a PlaceDetails.

Typing is debounced, so a request goes out only after the user pauses (300 ms by default) and only for input of at least minChars characters. Answers to older input are dropped. One session token covers the requests of a search, and a new one starts after each selection.

The default provider is PhotonPlacesProvider, which needs no key.

Form f = new Form("Where to?", new BorderLayout());
PlacesAutocomplete search = new PlacesAutocomplete(new PhotonPlacesProvider());
search.addSelectionListener(new SuccessCallback<PlaceDetails>() {
    public void onSucess(PlaceDetails place) {
        Log.p(place.getName() + " at " + place.getLocation());
    }
});
f.add(BorderLayout.NORTH, search);
f.show();

UIIDs: PlacesAutocomplete for the container, PlacesAutocompleteField for the field and PlacesAutocompleteItem for each suggestion.

  • Constructor Details

    • PlacesAutocomplete

      public PlacesAutocomplete()
      Creates the component with the keyless Photon provider.
    • PlacesAutocomplete

      public PlacesAutocomplete(PlacesProvider provider)

      Creates the component.

      Parameters
      • provider: the place search service
  • Method Details

    • getField

      public TextField getField()

      The text field, to set a hint or style it.

      Returns

      the field

    • setLocationBias

      public void setLocationBias(LatLng bias)

      Prefers results near a point, such as the user's location.

      Parameters
      • bias: the point, or null
    • setDebounce

      public void setDebounce(int debounceMs)

      Sets the pause after typing before a search, 300 ms by default.

      Parameters
      • debounceMs: the delay in milliseconds
    • setMinChars

      public void setMinChars(int minChars)

      Sets the shortest input that searches, 3 by default.

      Parameters
      • minChars: the minimum length
    • addSelectionListener

      public void addSelectionListener(SuccessCallback<PlaceDetails> l)

      Adds a listener called on the EDT when the user picks a suggestion.

      Parameters
      • l: the listener
    • removeSelectionListener

      public void removeSelectionListener(SuccessCallback<PlaceDetails> l)

      Removes a selection listener.

      Parameters
      • l: the listener
    • addErrorListener

      public void addErrorListener(SuccessCallback<Throwable> l)

      Adds a listener told when a search or a details lookup fails. The list of suggestions is cleared either way, so stale ones are never offered.

      Parameters
      • l: receives the failure
    • removeErrorListener

      public void removeErrorListener(SuccessCallback<Throwable> l)

      Removes a listener added with #addErrorListener(SuccessCallback).

      Parameters
      • l: the listener
    • getSessionToken

      public String getSessionToken()

      The session token of the current search, created on first use.

      Returns

      the token

    • search

      public void search()
      Runs the search for the current text now, skipping the debounce.