简体   繁体   中英

How to implement a search for location in Android?

Basically, on button click, I want the user to input a keyword or an exact location name, and in a listview, I want to show all the locations that match the given keyword within a certain radius or state/region. I've read about Geocoder/Google Maps and stuff like that, but is there like any tutorials that go in depth on how to do what I'm trying to do? I'm pretty confused on the whole subject. Thanks.

I use to different ways:

1) Android Location Geocoder

Geocoder geocoder = new Geocoder(context);
List<Address> addresses = geocoder.getFromLocationName(locationName, MAX_RESULTS);

2) A HTTP request to the Google Maps Geocode API

HttpGet httpGet = new HttpGet("http://maps.google.com/maps/api/geocode/json?address=" + urlEncodedLocationName +"&region=" + region + "&language=" + userLanguage);
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(httpGet);
HttpEntity entity = response.getEntity();
String result = EntityUtils.toString(entity, UTF8_CHARSET);

I hope this help you!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM