Answer the question
In order to leave comments, you need to log in
How to show the nearest drivers to the point of departure?
Need help from experts. There is a taxi application, in it, when choosing a point of departure and delivery, it shows a fragment with a list of drivers, according to logic and meaning, it should show the drivers who are closest to the client, say, in some range. And in this case, it shows everyone by the date of registration. Can anyone help with this issue?
BottomSheetFragmentBookingDriver which displays a list of all drivers
https://codeshare.io/GAMo1x
MainActivity
https://codeshare.io/5DOmEk
java
In MainActivity update the location of the driver
/** 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) {
}
@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;
}
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() {
}
}
Answer the question
In order to leave comments, you need to log in
Method in the forehead.
Request through geomap the primitives of the car within a radius of 1,2,3,4,5 and so on kilometers.
Then, using api yandex map, select the length of the route for each car.
Then look at their employment. Suppose a busy car 5 km away is more profitable than a free car 20 km away if it is quickly released.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question