@Override protected String doInBackground(String... params) { // TODO Check for location via GPS OR WIFI // LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); // Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); DateFormat dateFormat = new SimpleDateFormat("yyyymmdd"); // get current date time with Date() Date thisdate = new Date(); String currentDateandTime = dateFormat.format(thisdate).toString(); double[] latlong = getGPS(); curLat = latlong[0]; curLong = latlong[1]; String latLong = Double.toString(curLat) + "," + Double.toString(curLong); // String latLong = "38.918685,-77.019653"; DefaultHttpClient httpclient = new DefaultHttpClient(); final HttpParams httpParams = httpclient.getParams(); HttpConnectionParams.setConnectionTimeout(httpParams, 30000); HttpConnectionParams.setSoTimeout(httpParams, 30000); HttpGet httppost = new HttpGet( "https://api.foursquare.com/v2/venues/search?intent=checkin&ll=" + latLong + "&client_id=" + CLIENT_ID + "&client_secret=" + CLIENT_SECRET + "&v=" + currentDateandTime + "&categoryId=4bf58dd8d48988d17f941735&limit=20"); // try { HttpResponse response = httpclient.execute(httppost); // response class to handle responses jsonResult = inputStreamToString(response.getEntity().getContent()).toString(); /** The parsing of the xml data is done in a non-ui thread */ ListViewLoaderTask listViewLoaderTask = new ListViewLoaderTask(); /** Start parsing xml data */ listViewLoaderTask.execute(jsonResult); } catch (ConnectTimeoutException e) { Toast.makeText(getApplicationContext(), "No Internet", Toast.LENGTH_LONG).show(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return jsonResult; }
@Override protected void onPostExecute(String result) { // The parsing of the xml data is done in a non-ui thread ListViewLoaderTask listViewLoaderTask = new ListViewLoaderTask(); // Start parsing xml data listViewLoaderTask.execute(result); }