Нужна помощь экспертов. Есть приложение такси, в нем при выборе точки отправки и доставки, показывает фрагмент с списком водителей, по логике и смыслу должно показывать водителей которые ближе всего находятся к клиенту, скажем в каком то диапазоне. А в данном случае показывает всех по дате регистрации. Может кто сможет помочь с этим вопросом?
BottomSheetFragmentBookingDriver в котором выводятся список всех водителей
https://codeshare.io/GAMo1x
MainActivity
https://codeshare.io/5DOmEk
java
В MainActivity обновление место положения водителя
/** MAJ de la position d'un conducteur **/
private class setCurrentLocation extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
String url = AppConst.Server_url+"set_position.php";
final String latitude = params[0];
final String longitude = params[1];
StringRequest jsonObjReq = new StringRequest(Request.Method.POST,
url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("id_user", M.getID(context));
params.put("user_cat", M.getUserCategorie(context));
params.put("latitude", latitude);
params.put("longitude", longitude);
return params;
}
};
AppController.getInstance().addToRequestQueue(jsonObjReq);
jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(
10000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
return null;
}
@Override
protected void onPostExecute(String result) {
//to add spacing between cards
if (this != null) {
}
}
@Override
protected void onPreExecute() {
}
}
/** Start COOGLE API Client **/
@Override
public void onStart() {
super.onStart();
if (googleApiClient != null) {
googleApiClient.connect();
}
}
@Override
public void onStop() {
super.onStop();
if (googleApiClient != null) {
googleApiClient.disconnect();
}
}
@Override
public void onConnected(@Nullable Bundle bundle) {
if (ActivityCompat.checkSelfPermission(context,
Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(context,
Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
// Permissions ok, we get last location
currentLocation = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
startLocationUpdates();
}
private void startLocationUpdates() {
locationRequest = new LocationRequest();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(UPDATE_INTERVAL);
locationRequest.setFastestInterval(FASTEST_INTERVAL);
if (ActivityCompat.checkSelfPermission(context,
Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(context,
Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// Toast.makeText(this, "You need to enable permissions to display location !", Toast.LENGTH_SHORT).show();
}
LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this);
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
}
BottomSheetFragmentBookingDriver получение этих данных
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("lat1", String.valueOf(loc1.getLatitude()));
params.put("lng1", String.valueOf(loc1.getLongitude()));
params.put("type_vehicle", id_type_vehicle);
return params;
}
Сохранение заявки в BottomSheetFragmentBookingDriver
private class setRide extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
String url = AppConst.Server_url+"set_requete.php";
final String img_data = params[0];
StringRequest jsonObjReq = new StringRequest(Request.Method.POST,
url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject json = new JSONObject(response);
JSONObject msg = json.getJSONObject("msg");
String etat = msg.getString("etat");
if(etat.equals("1")){
dialogSucess();
// Toast.makeText(activity, context.getResources().getString(R.string.your_booking_as_been_sent_successfully), Toast.LENGTH_LONG).show();
}else{
Toast.makeText(activity, context.getResources().getString(R.string.an_error_occurred_while_sending_your_booking), Toast.LENGTH_LONG).show();
}
M.hideLoadingDialog();
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
M.hideLoadingDialog();
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("user_id", M.getID(context));
params.put("lat1", String.valueOf(loc1.getLatitude()));
params.put("lng1", String.valueOf(loc1.getLongitude()));
params.put("lat2", String.valueOf(loc2.getLatitude()));
params.put("lng2", String.valueOf(loc2.getLongitude()));
params.put("cout", cout);
params.put("distance", distance_init);
params.put("duree", duration);
params.put("id_conducteur", id_driver);
params.put("id_payment", id_payment);
params.put("depart_name", depart_name);
params.put("destination_name", destination_name);
params.put("place", place);
params.put("number_poeple", number_people);
params.put("image", img_data);
params.put("image_name", "recu_trajet_image_"+System.currentTimeMillis()+".jpg");
params.put("statut_round", statut_round);
if(statut_round.equals("yes")) {
params.put("date_retour", val_date_depart);
}else{
params.put("date_retour", "");
params.put("heure_retour", "");
}
return params;
}
};
AppController.getInstance().addToRequestQueue(jsonObjReq);
jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(
10000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
return null;
}
@Override
protected void onPostExecute(String result) {
//to add spacing between cards
if (this != null) {
}
}
@Override
protected void onPreExecute() {
}
}