/** * 中心点的数据处理 * * @param point */ private void getAddress(LatLng point) { // 0. 设置中心位置 aMap.moveCamera(CameraUpdateFactory.changeLatLng(point)); aMap.moveCamera( CameraUpdateFactory.zoomTo(Integer.valueOf(getString(R.string.default_me_zoomlevel)))); // 1. 清楚地图上的marker aMap.clear(); // 2. 将地理坐标转换为中文地址 mainMarkerLatLng = point; LatLonPoint latLonPoint = new LatLonPoint(point.latitude, point.longitude); GeocodeSearch geocoderSearch = new GeocodeSearch(this); geocoderSearch.setOnGeocodeSearchListener(this); // latLonPoint参数表示一个Latlng,第二参数表示范围多少米,GeocodeSearch.AMAP表示是国测局坐标系还是GPS原生坐标系 RegeocodeQuery query = new RegeocodeQuery(latLonPoint, 100, GeocodeSearch.AMAP); geocoderSearch.getFromLocationAsyn(query); // 设置同步逆地理编码请求 // 3. 将坐标发送给服务器, 请求附近的停车场的坐标与停车场的信息 // 初始化url String databaseUrl = null; databaseUrl = ParkingHttp.AddUrlType(databaseUrl, ParkingHttp.JSON_BASE_DATA); databaseUrl = ParkingHttp.AddUrlParms(databaseUrl, ParkingHttp.JSON_LAT, String.valueOf(point.latitude)); databaseUrl = ParkingHttp.AddUrlParms(databaseUrl, ParkingHttp.JSON_LNG, String.valueOf(point.longitude)); databaseUrl = ParkingHttp.AddUrlParms(databaseUrl, ParkingHttp.JSON_RANGE, RANGE_1000); Log.e(TAG, databaseUrl); if (downloadTask != null) Log.e(TAG, String.valueOf(downloadTask.cancel(true))); downloadTask = new DownloadTask(); downloadTask.execute(databaseUrl); // 4. 将这些信息绘制在地图上 }
/** * Uses the logging framework to display the output of the fetch operation in the log fragment. */ @Override protected void onPostExecute(String result) { // TODO Auto-generated method stub super.onPostExecute(result); Log.e(TAG, result); parkingInfoBaseList = ParkingHttp.parseJsonMulti( "{'baseInfo':[{'ID':15,'ParkingName':SongeekParking,'lat':26.10782268,'lng':119.273202667,'TotalParkingNumber':500,'FreeParkingNumber':200}]}"); // parkingInfoBaseList = ParkingHttp.parseJsonMulti(result); Message msg = Message.obtain(callback_handler, msg_type.CLB_REFRESH_AssistMarkers.ordinal()); msg.sendToTarget(); }
@Override protected String doInBackground(String... urls) { // TODO Auto-generated method stub try { return ParkingHttp.loadFromNetwork(urls[0]); } catch (IOException e) { return getString(R.string.error_network); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); return getString(R.string.error_network); } }