Back to Documentation Overview

Optimize Pickup/Dropoff Locations

In certain dispatch situations, there will be cases where a pick-up or drop-off is requested to a position that's difficult to reach for a vehicle. For example, if a passenger requests to be picked up from inside of an airport, their coordinates might not be reachable by the vehicle that's assigned to their task. To solve this issue, you can use the Pickup/Dropoff API to intelligently snap the input location on the road that is easily accessible by the vehicle.

In this guide, we'll run through an example where a passenger requests a trip from inside of an airport using the Dispatch API. Before we send the request, we will use the Pickup/Dropoff API to fetch a location on the road that is easily accessible by both the passenger as well as the vehicle. We can then use these coordinates as part of our request to the Dispatch API to pickup the passenger from a more optimal location.

Pickup/Dropoff Request

We'll begin by sending the passenger's location to the Pickup/Dropoff API in order to retrieve a more easily accessible set of coordinates.

# Pick-up location inside an airport
curl --request POST https://api.rideos.ai/pudo/v1/GetRoutablePositions \
--header "Content-Type: application/json" \
--header "X-Api-Key: $RIDEOS_API_KEY" \
--data '{
          "positions": [
            {
              "latitude": 32.897650,
              "longitude": -97.035627
            }
          ]
        }'

We'll then receive a routablePositions object that contains the latitude and longitude of the more optimal pickup location.

# Response with the optimized pick-up location
{
  "routablePositions": [
    {
      "latitude": 32.89737089044679,
      "longitude": -97.03623661474755
    }
  ]
}

Dispatch Request

We can then use these new coordinates retrieved from the Pickup/Dropoff API in our dispatch request, ensuring that the driver will be able to pick up the passenger. For Dispatch, we're going to assume that a fleet/vehicles have already been initialized, if you want to learn more about the Dispatch API in a ridehail context you can take a look at this guide. All we need to do then is to send a request using the coordinates provided in the response of the Pickup/Dropoff API.

# Dispatch request with optimized pickup/dropoff coordinates
curl --request POST https://api.rideos.ai/dispatch-tasks/v3/CreateTask \
--header "Content-Type: application/json" \
--header "X-Api-Key: $RIDEOS_API_KEY" \
--data '{"taskId":"task-1","fleetId":"fleet-test","taskDefinition":{"pickupDropoffTask":{"uniqueResourcePickup":{"pickupLocation":{"position":{"latitude":32.84593,"longitude":-96.84992}},"uniqueResource":{"requiredCapacities":[{"capacityType":"seats","value":2}],"metadata":{"data":{"rider-name":"Rider test 1","rider-phone":"123-4567","rider-url":"web.com"}}}},"dropoff":{"position":{"latitude":31.802372,"longitude":-97.418729}}},"requestorId":"rider-1"}}'

And that's about it! Any situation where the passenger's location might be unclear can be remedied by using the Pickup/Dropoff API prior to any requests being made.