Friday, 14 February 2014

Google places auto completed in android example

Google places auto completed in android example

          Here,i have written sample coding for getting the places autocompleted text in android.by using this you can get the places name from your text.


First,you have to create the AutoCompleteTextView.


AutoCompleteTextView ed;
ed=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);





Then you have to create the Arraylist to store the suggest names.and 
Then ,create TextWatcher() to detect the text changes.


ArrayList names;
names=new ArrayList<String>();
ed.addTextChangedListener(new TextWatcher()
{
public void afterTextChanged(Editable s)
{}
public void beforeTextChanged(CharSequence s, int start,
int count, int after)
{
}
public void onTextChanged(CharSequence s, int start,
int before, int count)
{
}
});


Then,Create URL from your input text



search_text= ed.getText().toString().split(",");
url="https://maps.googleapis.com/maps/api/place/autocomplete/json?input="+search_text[0]+"&sensor=true&key=YOUR BROWSER KEY";




Then,Parse the value from the JSON/XML webservice.


names=new ArrayList<String>();
Log.d("URL",url);
paserdata parse=new paserdata();
parse.execute();




Finally,set the values to the AutoCompleteTextView adapter,


adp=newArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_list_item_1s);
ed.setAdapter(adp);


Screenshot:







12 comments:

Unknown said...

i have downloaded and run the apk file from your link,,,, but the autocomplet does not work
what is the reson??

Unknown said...

i have also tryed to chainge to my api key (after ajasting the google api data to allow answer this app

Unknown said...

super simple and super awesome dude :) :)

Velmurugan said...

Please change the API key.

Velmurugan said...

Thanks

Sr. PiƱa said...

Thanks for this.
Very helpful, sadly I can't get it to work.
Where you say to put my "browser key" is that the place where I should put my API key? The apps keeps crashing after a few seconds!

Velmurugan said...

Hi.This is not API key.Please check your project in google api console,that having Browser key or you can create it..

Unknown said...

I've tried with browser key and api key. It doesn't work(

Unknown said...

I get a NATIVECRYPTO error when I run this sample,
Thank you any help would be much appreciated.

E-fusion Webservices said...

i have error into this in my case This IP, site or mobile application is not authorized to use this API key. Request received from IP address 117.212.90.72, with empty referer

E-fusion Webservices said...

please email my problem if resolve it

Velmurugan said...

Please check this link,
http://stackoverflow.com/questions/21933247/this-ip-site-or-mobile-application-is-not-authorized-to-use-this-api-key