codeScriber
codeScriber

Reputation: 4612

Places autocomplete for android devices

I need autocomplete functionality for both street anems and buinesses. the geoCoder from the location package is not giving me what i need. I checked the google labs Places JSON API but the responses from that request gives u only places names and ID not the lat long, for that you need an extra response which might make it slower to show auto completed location on map.

Is there any other api that a response should contain Boh the names and the last\long (take into account that i will not have ncessarily lat long for the request itself since i might be looking for places in a very remote place that is not related to my current location.

Upvotes: 1

Views: 803

Answers (1)

codeScriber
codeScriber

Reputation: 4612

This is what I've found through much searching:

Basically the JSON API for places API from google has two functionalities, one to search for locations and one for autocomplete, both hidden in the LABS code under PLACES API. To make it worth the while:

  1. implement some kind of connection pool or request\response pool to have several requests available for you if you wnat to cancel it in the middle or kill it altogether you have to have this kind of queue. LWUIT IO can be a good base to start from.
  2. when the user types text in an EditText use TextWatcher to sent autocomplete requests, kill the previous request if it has not arrived yet and display in a ListView the results so the user can pick an option.
  3. in your Layout there should also be a search button. if the user chose an autocomplete item from the List just put in in the EditText (make sure to switch off the textWatcher while you do that, switch it back on afterwards!), if the user press on search perform a search JSON request and show the result in a different ListView.

This is pretty much what the Javasciript API gives you in a more convenient manner. You can always use a WebView with maps api java script and a map and pass on callbacks to the WebView JS using android JavaScriptInterfaces.

Upvotes: 1

Related Questions