public void sendRequest(final Activity activity) { if (isFromEvent) { getEndpointLoc(activity); } else { String startAddressToGoogle = startAddress.replaceAll(" ", "+"); final String url = "https://maps.googleapis.com/maps/api/geocode/json?" + "address=" + startAddressToGoogle + ",+Australia&" + "key=AIzaSyBhEI1X-PMslBS2Ggq35bOncxT05mWO9bs"; final StringRequest getStartLocRequest = new StringRequest( Request.Method.GET, url, new Response.Listener<String>() { public void onResponse(String response) { try { JSONObject jsonResponse = new JSONObject(response); System.out.println(jsonResponse.toString()); latS = jsonResponse .getJSONArray("results") .getJSONObject(0) .getJSONObject("geometry") .getJSONObject("location") .getString("lat"); lonS = jsonResponse .getJSONArray("results") .getJSONObject(0) .getJSONObject("geometry") .getJSONObject("location") .getString("lng"); // Check response whether it's accurate, if not remind user } catch (Exception e) { e.printStackTrace(); } getEndpointLoc(activity); } }, new Response.ErrorListener() { public void onErrorResponse(VolleyError volleyError) { volleyError.printStackTrace(); System.out.println("it doesn't work"); } }); MyRequestQueue.getInstance(activity).addToRequestQueue(getStartLocRequest); } }
// reverse Address public void reverseAddress(final Activity activity) { final String url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + latC + "," + lonC + "&key=AIzaSyBhEI1X-PMslBS2Ggq35bOncxT05mWO9bs"; final StringRequest getCurrentAddressRequest = new StringRequest( Request.Method.GET, url, new Response.Listener<String>() { public void onResponse(String response) { try { JSONObject jsonResponse = new JSONObject(response); System.out.println(jsonResponse.toString()); currentAddress = jsonResponse .getJSONArray("results") .getJSONObject(0) .getString("formatted_address"); if (FromCurrentLocation.isChecked()) { EditStart.setHint(currentAddress); } if (ToCurrentLocation.isChecked()) { EditEnd.setHint(currentAddress); } } catch (Exception e) { e.printStackTrace(); } } }, new Response.ErrorListener() { public void onErrorResponse(VolleyError volleyError) { volleyError.printStackTrace(); System.out.println("it doesn't work"); } }); MyRequestQueue.getInstance(activity).addToRequestQueue(getCurrentAddressRequest); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); signedIn = false; // Initialize request queue MyRequestQueue.getInstance(this.getApplicationContext()).getRequestQueue(); this.savedInstanceState = savedInstanceState; // Build GoogleApiClient with access to basic profile mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(Plus.API) .addScope(new Scope(Scopes.PROFILE)) .build(); mGoogleApiClient.connect(); }
private void sendRideInfo(final Activity activity) { StringRequest OfferRequest = new StringRequest( Request.Method.POST, OFFER_RIDE_URL, new Response.Listener<String>() { @Override public void onResponse(String s) { activity.finish(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { volleyError.printStackTrace(); System.out.println("Sending post failed!"); } }) { protected Map<String, String> getParams() { Map<String, String> params = new HashMap<>(); System.out.println("fallie testing" + latS + lonS); if (FromCurrentLocation.isChecked()) { params.put("s_lat", Double.toString(latC)); params.put("s_lon", Double.toString(lonC)); params.put("start_add", currentAddress); } else { params.put("s_lat", latS); params.put("s_lon", lonS); params.put("start_add", startAddress); } if (ToCurrentLocation.isChecked()) { params.put("e_lat", Double.toString(latC)); params.put("e_lon", Double.toString(lonC)); params.put("destination", currentAddress); } else { params.put("e_lat", latE); params.put("e_lon", lonE); params.put("destination", endAddress); } if (isGroup) { params.put("group_id", groupId); } if (isEvent) { params.put("event_id", eventId); } params.put("seat", SeatNo); params.put("start_time", EditStartTime); params.put("arrival_time", EditEndTime); params.put("username", User.getCurrentUser().getUsername()); // params.put("token", MainActivity.getAuthToken(activity.getApplicationContext())); return params; } }; MyRequestQueue.getInstance(activity).addToRequestQueue(OfferRequest); }