I want to define a SuggestBox
, which behaves like the search bar in Google Maps: When you begin to type, real addresses, starting with the typed letters, appear.
I think, that I need to use the Geocoder.getLocations(String address, LocationCallback callback) method, but I have no idea how to connect this with the oracle, which is needed by the suggest box to produce its suggestions.
Can you please give me ideas how do I connect the getLocations
Method with the SuggestOracle
?
I solved this by implementing a subclass of
SuggestBox
, which has it's ownSuggestOracle
. TheAddressOracle
deals as a Wrapper for the Google Maps Service, for which the classGeocoder
in the Google Maps API for GWT offers abstractions.So here is my solution:
First we implement the Widget for a SuggestBox with Google Maps suggestions
Then we implement the SuggestOracle, which wraps the Geocoder async method abstractions:
And this is a special class for the oracle suggestions, which just represent a String with the delivered address.
Now you can bind the new widget into your web page by writing the following line in the
onModuleLoad()
-method of yourEntryPoint
-class: