Associate GPS Sensor Data (IoT) to a Route
See files for this Use Case on the GitHub here
You can associate GPS tracking data to a route and use for tracking of the packages IoT applications.
Description
Nowadays Internet connection extends to non-computer physical objects. A connected vehicle can receive swift information about weather, new avoidance zones and geofences. A connected pallet for example, can tell to its owner about the current location and condition of the shipment. A connected street light can sense the presence of cars and send environmental conditions to drivers. An user of our Route4Me API can receive information about logistic activities by callback url etc.
Let us consider AV fleet with five vehicles. The vehicles can communicate during trip and they can interchange an information instantly. For example, if several vehicles have to go through same road and first one discovered that there are some obstacles on the road, it can send information about obstacles to others and they will reoptimize their routes according to the new circumstance. Or Because of an obstacle one could be out of schedule and other one can deliver similar package (for example, bottles of milk) to destination instead it - in this case they can interchange package ID between them and after avoiding the obstacle first vehicle can deliver package to the appropriate destination.
Solution
Optimization Parameters and addresses
Let's create a route with just 2 destinations, round trip type. Here are the parameters for an optimization problem:
Parameter | Type | Description | HTTP method |
---|---|---|---|
api_key | string | API KEY of the user | GET |
redirect | integer | if equal to 1, will be redirected, if 0 - not | GET |
addresses | array | Valid JSON array of Address objects. Click here to see the JSON Schema | POST |
parameters | Route Parameters | Valid JSON string of RouteParameters object. Click here to see the JSON Schema | POST |
You can see the addresses on the map as:

Create an Optimization
You can create new optimization for this use case example. From the cUrl example bellow you can see that:
- the endpoint for this task is: https://www.route4me.com/api.v4/optimization_problem.php
- input data is stored in the file single_driver_round_trip_data.json
Parameter | Type | Description |
---|---|---|
api_key | string | API KEY of the user |
input data | POST data | Valid JSON object string. Click here to see the JSON Schema |
You can expect an Optimization problem (see link), which generated a route already.
View the Optimization details
You can get more details from the newly created optimization problem:
The endpoint: https://www.route4me.com/api.v4/optimization_problem.php
HTTP Parameters
Attribute | Type | Description | HTTP method |
---|---|---|---|
api_key | string | API KEY of the user | GET |
optimization_problem_id | string | Optimization problem ID | GET |
See sample RESPONSE JSON data here
Details of the Optimized Route
You can get more details of this route:
The endpoint: https://www.route4me.com/api.v4/route.php
HTTP Parameters
Attribute | Type | Description | HTTP method |
---|---|---|---|
api_key | string | API KEY of the user | GET |
route_id | string | Route ID | GET |
route_path_output | string | If equal to 'Poitns', you'll get an array of the path points to next address | GET |
See sample RESPONSE JSON data here
- Note
- In the RESPONSE you can see the array of the fields path_to_next. Those will be used to draw routes on a map, exactly as they generated by Route4Me API.
You can draw generated round trip route as:

Add Orders with Custom Data to the Route
You can add the orders to the route. The orders should contain custom data with item name, because we are going to search item's route and GPS position later.
The endpoint: https://route4me.com/api.v4/optimization_problem.php
HTTP Parameters
Attribute | Type | Description | HTTP method |
---|---|---|---|
api_key | string | API KEY of the user | GET |
optimization_problem_id | string | Optimization problem ID | GET |
redirect | intenger | If equal to 1, will be redirected | GET |
Addresses | array | Valid JSON string of the Address objects array | POST |
See sample INPUT JSON data here
Pay attention to the parameters into the custom data:
See sample RESPONSE JSON data here
You can do following steps again as they described above:
- View the Optimization details;
- Details of the Optimized Route.
and see that the optimization problem now has the same route with 2 stops, but additional unrouted destinations.
Reoptimize Optimization
In order to reshape the route including new addresses, you can reoptimize the existing optimization.
The endpoint: https://www.route4me.com/api.v4/optimization_problem.php
HTTP Parameters
Attribute | Type | Description | HTTP method |
---|---|---|---|
api_key | string | API KEY of the user | GET |
optimization_problem_id | string | Optimization problem ID | GET |
reoptimize | integer | If equal to 1, the optimization problem will be reoptimized | GET |
Route Parameters | object | Valid JSON object string. Click here to see the JSON Schema | GET |
Addresses | array | Valid JSON string of the Address objects. Click here to see the JSON Schema | GET |
- Note
- After reoptimization the parameter route_id of the routes could be changed.
You can expect this API response:
You can do following steps again as they described above:
- View the Optimization details (see sample RESPONSE JSON data here);
- Details of the Optimized Route (see sample RESPONSE JSON data here).
and see that now you have the reoptimized route with 8 destinations.
You can draw the reoptimized route on a map as:

Find a Route Containing the Asset
You can find a route containing specified asset by custom data. As you can find in the input JSON file (see the file here) for the topic Add Orders with Custom Data to the Route, the order has custom data:
The endpoint: https://www.route4me.com/api.v4/route.php
HTTP Parameters
Attribute | Type | Description | HTTP method |
---|---|---|---|
api_key | string | API KEY of the user | GET |
query | string | Query string | GET |
See sample response JSON data here.
Pay attention to the parameter route_id:
Set GPS position of a vehicle
Many vehicles are equipped with GPS devices. With our API, you can manually set a GPS position to the vehicle and retrieve this information.
The endpoint: https://www.route4me.com/track/set.php
HTTP Parameters
Attribute | Type | Description | HTTP method |
---|---|---|---|
api_key | string | API KEY of the user | GET |
format | string | RESPONSE format | GET |
member_id | integer | User ID | GET |
route_id | string | Route ID | GET |
course | integer | The direction in degrees in which the vehicle is heading | GET |
speed | decimal | The speed with which the vehicle is moving | GET |
lat | double | Geographic Latitude | GET |
lng | double | Geographic Longitude | GET |
device_type | string | Device type ENUM(iphone, ipad, android_phone, android_tablet) | GET |
device_guid | string | Device ID | GET |
vehicle_id | string | Vehicle ID | GET |
You can expect this API response:
Retrieve an Asset Tracking Information
Now you can find a route containing the destination with the item, even if this destination was moved from initial route to other one.
The endpoint: https://route4me.com/api.v4/status.php
HTTP Parameters
Attribute | Type | Description | HTTP method |
---|---|---|---|
api_key | string | API KEY of the user | GET |
tracking | string | Asset unique internal ID | GET |
You can expect this API response:
You can draw the asset location on a map as:

Dynamic Re-optimization a Route After Receiving new Information
Suppose, your driver is on the route to the client and suddenly you receive the information about the new conditions along the route - e.g. high hills covered with snow or road construction ahead. Having this information, you want to re-optimize route.
You can read the article Create a polygon Territory Around a Geographic Area on how to construct the territorial and avoidance zones with Route4Me API. This time let us do that with Route4Me web UI.
Also you can read the article Receive Address Check-In Notifications to learn how to use Rout4eMe's callback feature.
We can draw an avoidance zone using Route4Me web UI and then draw it along with the route on the map using the open source tools:

When we created the avoidance zone with the Web UI, we named it as **"AvZone above Hudson"**. Please note that inside the parameter avoidance_zones you have to indicate the avoidance zone ID, not avoidance zone name. So, first you have to find out the avoidance zone ID.
The endpoint: https://www.route4me.com/api.v4/avoidance.php
HTTP Parameters
Attribute | Type | Description | HTTP method |
---|---|---|---|
api_key | string | API KEY of the user | GET |
See sample response JSON data here.
You can find in the JSON data that territory_id=29AACF4A1B5F38F50EF7A7EAF6DCAFAB for our avoidance zone.
Now you can re-optimize the optimization.
The endpoint: https://www.route4me.com/api.v4/optimization_problem.php
HTTP Parameters
Attribute | Type | Description | HTTP method |
---|---|---|---|
api_key | string | API KEY of the user | GET |
optimization_problem_id | string | Optimization problem ID | GET |
reoptimize | integer | If equal to 1, the optimization problem will be reoptimized | GET |
Route Parameters | object | Valid JSON object string. Click here to see the JSON Schema | GET |
Addresses | array | Valid JSON string of the Address objects. Click here to see the JSON Schema | GET |
See sample input JSON data here.
See sample response JSON data here.
You can do following steps again as they described above:
- View the Optimization details;
- Details of the Optimized Route.
and see that the optimized route avoided the avoidance zone. You can see it on a map as:
