Insert an Address into an Existing Route

See files for this Use Case on the GitHub here

Description

Route4Me allows you to add addresses at any time after a route was planned. You can insert them in a specific position into a route, or you can insert an address without specific position and allow system to find optimal position for this address.

Solution

Optimization Parameters and addresses

Let us choose a Single Driver Round Trip option for this use case. Here are parameters for an optimization problem:

ParameterTypeDescriptionHTTP method
api_keystringAPI KEY of the userGET
redirectintegerif equal to 1, will be redirected, if 0 - notGET
addressesarrayValid JSON array of Address objects. Click here to see the JSON SchemaPOST
parametersRoute ParametersValid JSON string of RouteParameters object. Click here to see the JSON SchemaPOST

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:

ParameterTypeDescription
api_keystringAPI KEY of the user
input dataPOST dataValid JSON object string. Click here to see the JSON Schema
1 @ECHO OFF
2 
3 :: Single Driver Round Trip
4 ::See video tutorial here: http://support.route4me.com/route-planning-help.php?id=manual0:tutorial2:chapter1:subchapter1
5 
6 SET URL=https://www.route4me.com/api.v4/optimization_problem.php
7 SET apikey=11111111111111111111111111111111
8 
9 ECHO ON
10 
11 curl -o file1.txt -g -X POST -k -d "@single_driver_round_trip_data.json" "%url%?api_key=%apikey%"
12 
13 timeout /t 30

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

AttributeTypeDescriptionHTTP
method
api_keystringAPI KEY of the userGET
optimization_problem_idstringOptimization problem IDGET


1 @ECHO OFF
2 
3 SET url=https://www.route4me.com/api.v4/optimization_problem.php
4 SET apikey=11111111111111111111111111111111
5 SET optprobid=11A4A5DEC02E82F8E8947E3F9D5D0404
6 
7 ECHO ON
8 curl -o file1.txt -g -X GET -k "%URL%?api_key=%apikey%&optimization_problem_id=%optprobid%"
9 
10 timeout /t 30

See sample RESPONSE JSON data here

The system will send a RESPONSE with an array of the addresses, which belongs to one round trip route.

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

AttributeTypeDescriptionHTTP
method
api_keystringAPI KEY of the userGET
route_idstringRoute IDGET
route_path_outputstringIf equal to 'Poitns', you'll get an array of the path points to next addressGET


1 @ECHO OFF
2 
3 SET url=https://www.route4me.com/api.v4/route.php
4 SET apikey=11111111111111111111111111111111
5 SET routeid=5F9F4AE9FA82B3AFABB531E94EFAE19D
6 SET rpo=Points
7 
8 ECHO ON
9 
10 curl -o file1.txt -g -k -X GET "%url%?route_id=%routeid%&api_key=%apikey%&route_path_output=%rpo%"
11 
12 timeout /t 30

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 an Address in a Specified Position

You can add an address in a specific position of a 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 POST
addresses array Valid JSON array of Address objects. Click here to see the JSON Schema POST
optimal_position boolean If true, an address will be inserted at optimal position of a route

POST


See sample INPUT JSON data here

1 @ECHO OFF
2 
3 SET url=https://www.route4me.com/api.v4/route.php
4 SET apikey=11111111111111111111111111111111
5 SET routeid=5F9F4AE9FA82B3AFABB531E94EFAE19D
6 
7 ECHO ON
8 
9 curl -o file1.txt -k -g -X PUT -H "Content-Type: application/json" -d "@add_addresses_to_route_spec_position_data.json" "%url%?route_id=%routeid%&api_key=%apikey%"
10 
11 timeout /t 30

See sample RESPONSE JSON data here

You can draw generated round trip route as:

As you can see, the route is reoptimized already.

Add an Address in an Optimal Position

You can add an address in an optimal postion of a 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 POST
addresses array Valid JSON array of Address objects. Click here to see the JSON Schema POST
optimal_position boolean If true, an address will be inserted at optimal position of a route

POST


See sample INPUT JSON data here

1 @ECHO OFF
2 
3 SET url=https://www.route4me.com/api.v4/route.php
4 SET apikey=11111111111111111111111111111111
5 SET routeid=5F9F4AE9FA82B3AFABB531E94EFAE19D
6 
7 ECHO ON
8 
9 curl -o file1.txt -k -g -X PUT -H "Content-Type: application/json" -d "@add_addresses_to_route_optim_position_data.json" "%url%?route_id=%routeid%&api_key=%apikey%"
10 
11 timeout /t 30

You can draw generated round trip route as:

As you can see, the address was inserted in optimal position (sequence number=1) and the route is optimized already.