如何在Android中实现搜索位置?

时间:2014-08-26 23:38:07

标签: android parsing location geocode

基本上,在按钮点击时,我希望用户输入关键字或确切的位置名称,在列表视图中,我想显示在特定半径或州/区域内与给定关键字匹配的所有位置。我已经阅读过有关Geocoder / Google Maps等内容的信息,但是有没有像我那样深入研究如何做我想做的事情的教程?我对整个主题感到很困惑。感谢。

1 个答案:

答案 0 :(得分:0)

我用不同的方式:

1)Android位置地理编码器

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

2)对Google Maps Geocode API的HTTP请求

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);

我希望这能帮到你!