Examples

View the position of vehicles on the map

List of vehicles with details

  • Car #185381
    • Registration number:
    • Mileage: 0 km
    • Position: invalid
    • Current speed: 0 km/h
    • Direction: 0
    • Started: No
  • Car #185382
    • Registration number:
    • Mileage: 0 km
    • Position: invalid
    • Current speed: 0 km/h
    • Direction: 0
    • Started: No
  • Car #17639
    • Registration number: 2M50009
    • Mileage: 1619.49 km
    • Position: 49.601625, 17.242227
    • Current speed: 0 km/h
    • Direction: 510
    • Started: No
  • Car #200854
    • Registration number: 3AB 4466
    • Mileage: 150953 km
    • Position: 49.468695, 17.101099
    • Current speed: 0 km/h
    • Direction: 156
    • Started: No
  • Car #174177
    • Registration number: 5AB 2198
    • Mileage: 376377.82 km
    • Position: 49.994065, 14.37664
    • Current speed: 0 km/h
    • Direction: 510
    • Started: No
  • Car #209726
    • Registration number: 5M2 3721
    • Mileage: 2573.73 km
    • Position: 49.59125, 17.250659
    • Current speed: 0 km/h
    • Direction: 314
    • Started: No
  • Car #48853
    • Registration number: 5M23721
    • Mileage: 1331.61 km
    • Position: 49.602312, 17.242463
    • Current speed: 0 km/h
    • Direction: 12
    • Started: No
  • Car #200862
    • Registration number: 5M3 4474
    • Mileage: 55858.56 km
    • Position: 49.602162, 17.242291
    • Current speed: 0 km/h
    • Direction: 34
    • Started: No
  • Car #120590
    • Registration number: 5M6 7728
    • Mileage: 65977.1 km
    • Position: 49.602333, 17.242463
    • Current speed: 0 km/h
    • Direction: 510
    • Started: No
  • Car #197045
    • Registration number: 5M6 7728 - Dongle full
    • Mileage: 65977.1 km
    • Position: 49.602333, 17.242441
    • Current speed: 0 km/h
    • Direction: 348
    • Started: No
  • Car #205049
    • Registration number: 5M6 7728 - OBU
    • Mileage: 1536.75 km
    • Position: 49.596797, 17.236776
    • Current speed: 0 km/h
    • Direction: 66
    • Started: No
  • Car #176146
    • Registration number: 6AX 1980
    • Mileage: 21968 km
    • Position: 49.602333, 17.242377
    • Current speed: 0 km/h
    • Direction: 190
    • Started: No
  • Car #176344
    • Registration number: 6AY 3091
    • Mileage: 119288.27 km
    • Position: 50.527084, 13.233483
    • Current speed: 0 km/h
    • Direction: 328
    • Started: No
  • Car #200860
    • Registration number: 9B32095
    • Mileage: 10395.85 km
    • Position: 49.467332, 17.128737
    • Current speed: 0 km/h
    • Direction: 358
    • Started: No
  • Car #189402
    • Registration number: S845X00001-dongl
    • Mileage: 11380 km
    • Position: 50.051174, 14.436142
    • Current speed: 0 km/h
    • Direction: 154
    • Started: No
  • Car #195322
    • Registration number: S845X00021
    • Mileage: 3178.55 km
    • Position: 49.60243, 17.241046
    • Current speed: 0 km/h
    • Direction: 212
    • Started: No
  • Car #195326
    • Registration number: S845X00030
    • Mileage: 0 km
    • Position: invalid
    • Current speed: 0 km/h
    • Direction: 0
    • Started: No
  • Car #195331
    • Registration number: S845X00031
    • Mileage: 0 km
    • Position: invalid
    • Current speed: 0 km/h
    • Direction: 0
    • Started: No
  • Car #186678
    • Registration number: S856X00013
    • Mileage: 11553.91 km
    • Position: 50.051936, 14.433203
    • Current speed: 0 km/h
    • Direction: 284
    • Started: No
  • Car #203741
    • Registration number: testovací BLE jednotka
    • Mileage: 21.98 km
    • Position: 49.611485, 17.252462
    • Current speed: 0 km/h
    • Direction: 510
    • Started: No
  • Car #191172
    • Registration number: testovací jednotka OBU
    • Mileage: 21964.27 km
    • Position: 49.601722, 17.241755
    • Current speed: 0 km/h
    • Direction: 0
    • Started: No
  • Car #185384
    • Registration number: TestSK
    • Mileage: 0 km
    • Position: invalid
    • Current speed: 0 km/h
    • Direction: 0
    • Started: No
  • Car #185383
    • Registration number: Test-SK
    • Mileage: 0 km
    • Position: invalid
    • Current speed: 0 km/h
    • Direction: 0
    • Started: No

Used functions

Used technologies and tools

Source code

<?php
// login data
$kodf = '****';
$username = '****';
$pass = '****';

$client = new \SoapClient('http://api.webdispecink.cz/code/WebDispecinkServiceNet.php?wsdl');

// array for list of cars
$cars = array();

// the _getCarsList () function returns also car registration number
$car_list = $client->_getCarsList($kodf, $username, $pass);

if (isset($car_list->item) &&
    is_array($car_list->item))
{
    foreach ($car_list->item as $car)
    {
        if ($car->disabled == 0)
        {
            $cars[$car->carid] = array(
                'identifier' => $car->identifikator      // car registration number
            );
        }
    }
}

// last parameter empty - position and other details of all available cars under the specified user
$car_positions = $client->_getCarsIDPosition2($kodf, $username, $pass, '');

if (isset($car_positions->item) &&
    is_array($car_positions->item))
{
    foreach ($car_positions->item as $position)
    {
        if (isset($cars[$position->cd]))
        {
            $cars[$position->cd] += array(                
                'latitude'  => (float)$position->Zs,        // latitude
                'longitude' => (float)$position->Zd,        // longitude
                'speed'  => (int)$position->sd,             // speed
                'running' => (bool)$position->EE,           // key voltage indicator (> 0 = started)
                'tachometer' => (float)$position->Km,       // odometer value
                'direction' => (int)$position->ca,          // driving direction
            );
        }
    }    
}
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <title>List of vehicles with details - API Webdispatching</title>        
    </head>
    <body>
        <ul>
<?php
foreach ($cars as $car_id => $car)
{
?>
            <li>
                <strong>Car #<?php echo htmlspecialchars($car_id); ?></strong>
                <ul>
                    <li>Registration number: <?php echo $car['identifier']; ?></li>
                    <li>Mileage: <?php echo $car['tachometer']; ?> km</li>
                    <li>Position: <?php echo ($car['latitude'] == 0 && $car['longitude'] == 0) ? 'invalid' : ($car['latitude'] . ', ' . $car['longitude']); ?></li>
                    <li>Current speed: <?php echo $car['speed']; ?> km/h</li>
                    <li>Direction: <?php echo $car['direction']; ?></li>
                    <li>Started: <?php echo $car['running'] ? "Yes" : "No"; ?></li>
                </ul>
            </li>
<?php
}
?>
        </ul>
    </body>
</html>

Used technologies and tools

Source code

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import javax.xml.soap.*;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class ExampleList
{
    // login data
    private static final String KODF = "****";
    private static final String USERNAME = "****";
    private static final String PASS = "****";
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        Map<Integer, CarInfo> cars = new HashMap<>();
        
        try
        {
            // create a connection for SOAP
            SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
            SOAPConnection soapConnection = soapConnectionFactory.createConnection();

            // calling parameters of function_getCarsList ()
            Map<String, String>parametersCarList = new HashMap<>();
            parametersCarList.put("kodf", KODF);
            parametersCarList.put("username", USERNAME);
            parametersCarList.put("pass", PASS);
            
            // SOAP server URL
            String url = "https://api.webdispecink.cz/code/WebDispecinkServiceNet.php?wsdl";
            
            // create a request with parameter for calling the function _getCarsList ()
            SOAPMessage soapRequestCarList = createSOAPRequest("_getCarsList", parametersCarList);
            // calling the function_getCarsList () to get the car registration number
            SOAPMessage soapResponseCarList = soapConnection.call(soapRequestCarList, url);
            
            /*
            Example of server response:

            <?xml version="1.0" encoding="UTF-8" standalone="no"?>
            <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn://api.webdispecink.cz/webdisser_02">
                <SOAP-ENV:Body>
                    <ns1:_getCarsListResponse>
                        <return>
                            <item>
                                <cargroupid>0</cargroupid>
                                <carid>1</carid>
                                <identifikator>1M5 76 86</identifikator>
                                ...
                            </item>
                            ...
                        </return>
                    </ns1:_getCarsListResponse>
                </SOAP-ENV:Body>
            </SOAP-ENV:Envelope>                    
            */
            
            // get response body - tag content <SOAP-ENV:Body>
            SOAPBody responseCarList = soapResponseCarList.getSOAPBody();
            // element <ns1:_getCarsListResponse>
            Node getAllCarsPositionResponse = responseCarList.getFirstChild();
            // element <return>
            Node returnContent = getAllCarsPositionResponse.getFirstChild();

            // list of elements <item>
            NodeList items = returnContent.getChildNodes();
            
            int i, j;
            // go through the returned car records
            for (i = 0; i < items.getLength(); i++)
            {
                Node item = items.item(i);
                NodeList data = item.getChildNodes();

                // create a new object of car to store the acquired data
                CarInfo car = new CarInfo();
                
                // browse all items of one record
                for (int k = 0; k < data.getLength(); k++)
                {
                    // text item content
                    String content = data.item(k).getTextContent();
                    
                    switch (data.item(k).getLocalName())
                    {     
                        // unique vehicle identifier
                        case "carid":
                            car.id = Integer.parseInt(content);
                            break;
                            
                        // car registration number
                        case "identifikator":
                            car.identifier = content;
                            break;
                        
                        // is the vehicle being tracked?
                        case "disabled":
                            car.disabled = content.compareTo("1") == 0;
                            break;
                    }
                }
                
                // saves the car for later editing
                cars.put(car.id, car);
            }
            
            // calling parameters of function _getCarsIDPosition2()
            Map<String, String>parametersCarPosition = new HashMap<>();
            parametersCarPosition.put("kodf", KODF);
            parametersCarPosition.put("username", USERNAME);
            parametersCarPosition.put("pass", PASS);
            parametersCarPosition.put("carid_list", "");

            // create a request with parameter for calling the function _getCarsIDPosition2()
            SOAPMessage soapRequestCarPosition = createSOAPRequest("_getCarsIDPosition2", parametersCarPosition);
            // calling the function _getCarsIDPosition2() function to get more data about the car
            SOAPMessage soapResponseCarPosition = soapConnection.call(soapRequestCarPosition, url);
            
            /*
            Example of server response:

            <?xml version="1.0" encoding="UTF-8" standalone="no"?>
            <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn://api.webdispecink.cz/webdisser_02">
                <SOAP-ENV:Body>
                    <ns1:_getCarsIDPosition2Response>
                        <return>
                            <item>
                                <cd>17641</cd>
                                <Zs>49.599318</Zs>
                                <Zd>17.247634</Zd>
                                ...                                        
                            </item>
                            ...
                        </return>
                    </ns1:_getCarsListResponse>
                </SOAP-ENV:Body>
            </SOAP-ENV:Envelope>                    
            */
            
            // get response body - tag content <SOAP-ENV:Body>
            SOAPBody responseCarPosition = soapResponseCarPosition.getSOAPBody();            
            // element <ns1:_getCarsIDPosition2>
            Node getCarsIDPosition2Response = responseCarPosition.getFirstChild();
            // element <return>
            returnContent = getCarsIDPosition2Response.getFirstChild();
            
            // browse elements <item>
            items = returnContent.getChildNodes();
            for (i = 0; i < items.getLength(); i++)
            {
                Node item = items.item(i);                
                NodeList data = item.getChildNodes();
                
                CarInfo car = null;                

                // find a vehicle according a unique identifier
                for (j = 0; j < data.getLength(); j++)
                {
                    if (data.item(j).getLocalName().compareTo("cd") == 0)
                    {
                        int id = Integer.parseInt(data.item(j).getTextContent());
                        car = cars.get(id);
                    }
                }
                
                // if vehicle wasn't found by id, continue by next
                if (car == null)
                {
                    continue;
                }                
                
                // browse all items of one record
                for (j = 0; j < data.getLength(); j++)
                {
                    // text item content
                    String content = data.item(j).getTextContent();
                    
                    // skip empty content
                    if (content.isEmpty())
                    {
                        continue;
                    }
                    
                    switch (data.item(j).getLocalName())
                    {
                        // latitude
                        case "Zs":
                            car.latitude = Float.parseFloat(content);
                            break;
                        
                        // longitude
                        case "Zd":
                            car.longitude = Float.parseFloat(content);
                            break;
                        
                        // speed
                        case "sd":
                            car.longitude = Integer.parseInt(content);
                            break;
                        
                        // key voltage indicator (> 0 = started)
                        case "EE":
                            car.running = Boolean.parseBoolean(content);
                            break;
                        
                        // odometer value
                        case "Km":
                            car.tachometer = Float.parseFloat(content);
                            break;
                        
                        // driving direction
                        case "ca":
                            car.direction = Integer.parseInt(content);
                            break;
                    }
                }
            }
            
            // closing the connection
            soapConnection.close();
            
            // list information about cars on the output
            for (Entry<Integer, CarInfo> entry : cars.entrySet())
            {
                CarInfo car = entry.getValue();
                
                // only watched cars
                if (car.disabled == false)
                {
                    System.out.println(car);
                }
            }
        }
        catch (Exception e)
        {
            System.err.println("Error occurred while handling SOAP Request.");
            e.printStackTrace();
        }
    }
    
    private static SOAPMessage createSOAPRequest(String functionName, Map<String, String> parameters) throws Exception
    {
        MessageFactory messageFactory = MessageFactory.newInstance();
        SOAPMessage soapMessage = messageFactory.createMessage();
        SOAPPart soapPart = soapMessage.getSOAPPart();

        // SOAP Envelope
        SOAPEnvelope envelope = soapPart.getEnvelope();

        // SOAP Body
        SOAPBody soapBody = envelope.getBody();
        SOAPElement soapBodyElem = soapBody.addChildElement(functionName);
        
        // adding parameters
        for (Entry<String, String> entry : parameters.entrySet())
        {
            String key = entry.getKey();
            String value = entry.getValue();
            SOAPElement paramKodf = soapBodyElem.addChildElement(key);
            paramKodf.addTextNode(value);
        }

        soapMessage.saveChanges();

        return soapMessage;
    }
}

public class CarInfo extends Object 
{
    public int id;                      // unique vehicle identifier
    public String identifier;           // car registration number
    public float latitude;              // latitude
    public float longitude;             // longitude
    public int speed;                   // speed
    public boolean running;             // is the vehicle started?
    public float tachometer;            // odometer value
    public int direction;               // driving direction
    public boolean disabled;            // is the vehicle being tracked?
    
    @Override
    public String toString()
    {
        String pattern = 
                "Car #%d%n" +
                "Car registration number: %s%n" +
                "Speedometer: %f km\n" +
                "Geographical location: %f, %f%n" +
                "Current speed: %d km/h%n" +
                "Direction: %d%n" +
                "Started: %s%n";

        String output = String.format(pattern, id, identifier, tachometer, latitude, longitude, speed, direction, running ? "Yes" : "No");

        return output;
    }
}