How to implement a search for location in Android?

此生再无相见时 提交于 2019-12-13 05:14:37

问题


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.


回答1:


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!



来源:https://stackoverflow.com/questions/25516791/how-to-implement-a-search-for-location-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!