/** * 根据城市名称获取经纬度 *  * @param city        城市中文名称、拼音、英文 * @return location         经纬度数组,0为经度,1为纬度 */private String[] getLocationByCityName(String city) {String[] location = new String[2];try {HttpClient httpClient = new DefaultHttpClient();HttpPost httpPost = new HttpPost("http://maps.google.com/maps/geo?q=" + city);int res = 0;res = httpClient.execute(httpPost).getStatusLine().getStatusCode();if (res == 200) {/* * 当返回码为200时,做处理 得到服务器端返回json数据,并做处理 */HttpResponse httpResponse = httpClient.execute(httpPost);StringBuilder builder = new StringBuilder();BufferedReader bufferedReader2 = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent()));for (String s = bufferedReader2.readLine(); s != null; s = bufferedReader2.readLine()) {builder.append(s);}/** * 这里需要分析服务器回传的json格式数据, */JSONObject jsonObject = new JSONObject(builder.toString());JSONArray jsonArray = jsonObject.getJSONArray("Placemark");for (int i = 0; i < jsonArray.length(); i++) {JSONObject jsonObject2 = (JSONObject) jsonArray.opt(i);JSONObject jsonObject3 = new JSONObject(jsonObject2.getString("Point"));JSONArray jsonArray1 = jsonObject3.getJSONArray("coordinates");location[0] = (String) jsonArray1.get(0);location[1] = (String) jsonArray1.get(1);}}} catch (ClientProtocolException e) {e.printStackTrace();} catch (IllegalStateException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();} catch (JSONException e) {e.printStackTrace();}return location;}});

更多相关文章

  1. Android高级工程师成长路线
  2. Android程序开发之数据存储(一): 使用sqlite 进行登录注册
  3. Android解析XML(PULL)展示到ListView
  4. Android(安卓)压缩工具类
  5. android googleMap使用并在指定的位置上标注
  6. Android(安卓)Sqlite的增、删、改、查
  7. Android(安卓)-- PullToRefresh应用
  8. 锦囊篇|一文摸懂RxJava
  9. android实现xml数据的解析

随机推荐

  1. Android(安卓)Spinner与适配器模式详解及
  2. Android温故之-BroadcastReceiver
  3. android实现横向滚动
  4. Android(安卓)的木马危机
  5. Android新手入门2016(2)--Mac下的Android开
  6. 【Android】在不同的线程池中执行AsyncTa
  7. 用c#开发安卓程序 (xamarin.android)系列
  8. [置顶] [Android(安卓)Studio 权威教程]Win
  9. 【30篇突击 android】源码统计 十九
  10. eclipse 上调试android的自带应用方法