MapView 的 getFromLocationName, 模糊范围的搜寻
时间:2011-09-30
来源:互联网
Greeting ,
我可以使用 Google map 定位自己的位置,使用 MapView , 也会跟者人移到而一起移动
我可以使用 Google map 定位自己的位置,使用 MapView , 也会跟者人移到而一起移动
作者: shanchieh 发布时间: 2011-09-30
刚刚我做一个测试,使用 Google map api 来达到我要的功能,程式码:
这是可以执行,但是查出来的结果一样很怪,他使用 map 查询
1 |
public class MapUtility { public static JSONObject getLocationInfo(String address) { HttpGet httpGet = new HttpGet("http://maps.google." + "com/maps/api/geocode/json?address=" + address + "&sensor=false"); HttpClient client = new DefaultHttpClient(); HttpResponse response; StringBuilder stringBuilder = new StringBuilder(); try { response = client.execute(httpGet); HttpEntity entity = response.getEntity(); InputStream stream = entity.getContent(); int b; while ((b = stream.read()) != -1) { stringBuilder.append((char) b); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } JSONObject jsonObject = new JSONObject(); try { jsonObject = new JSONObject(stringBuilder.toString()); } catch (JSONException e) { e.printStackTrace(); } return jsonObject; } // converts JSONObject into a GeoPoint. public static GeoPoint getGeoPoint(JSONObject jsonObject) { Double lon = new Double(0); Double lat = new Double(0); try { lon = ((JSONArray) jsonObject.get("results")).getJSONObject(0) .getJSONObject("geometry").getJSONObject("location") .getDouble("lng"); lat = ((JSONArray) jsonObject.get("results")).getJSONObject(0) .getJSONObject("geometry").getJSONObject("location") .getDouble("lat"); } catch (JSONException e) { e.printStackTrace(); } return new GeoPoint((int) (lat * 1E6), (int) (lon * 1E6)); } } |
这是可以执行,但是查出来的结果一样很怪,他使用 map 查询
作者: shanchieh 发布时间: 2011-09-30
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28