Skip to main content
Omnitracs Knowledge Base

Display the Vehicle Information

The following changes will display proximity information that was retrieved by the getVehicleInformation call.

Place a large, multiline label control onto your form.
09DemoFormLabel.jpg
Set its properties:
Text: Place to display the vehicle information.
Name: lblVehicleInfo

Add the following code as necessary to make your button handler present the proximity data from the VehicleInfo object. You will need to add a reference to System.Text to support the StringBuilder.

using System.Text;

private void btnGetInfo_Click(object sender, System.EventArgs e)

{

    // The getVehicleInformation method accepts an AssetIdentifier and returns a

    // VehicleInfo object.  Instantiate them both.

    qtref.AssetIdentifier ai = new qtref.AssetIdentifier();

    qtref.VehicleInfo vi = new qtref.VehicleInfo();

 

    // Replace these strings with valid company name, user name and password

    string sUsername = "theusername";

    string sCompanyname = "thecompanyname";

    string sIdentity = sUsername + "@" + sCompanyname;

    string sPassword = "thepassword";

 

    // Create the SOAP context and token.  Put the identity and password into the token

    // and add the token to the context.

    SoapContext requestContext = svc.RequestSoapContext;

    UsernameToken userToken = new UsernameToken(sIdentity, sPassword, PasswordOption.SendPlainText);

    requestContext.Security.Tokens.Clear();

    requestContext.Security.Tokens.Add(userToken);

 

    try

    {

        ai.scac = "   ";    // No SCACs required at this time.

        ai.id = "CSDIMCT";  // Replace with the ID of a vehicle in your fleet

        vi = svc.getVehicleInformation(ai); // Invoke the service

 

        // Format some of the resulting vehicle information into a string and

        // display it.

 

        StringBuilder sb = new StringBuilder("");

        sb.Append("Identifier: ");

        sb.Append(vi.vehicle.id);

        sb.Append("   Name:  ");

 

        sb.Append("\nPosition Hardware:  ");

        sb.Append(vi.positionHardware);

 

        sb.AppendFormat("\nDistance: {0} Direction: {1}  {2}, {3}  {4}  {5}  Type: {6} Name: {7}",

            vi.proximityTown.distance, vi.proximityTown.direction, vi.proximityTown.city, vi.proximityTown.state,

            vi.proximityTown.zip, vi.proximityTown.country, vi.proximityTown.placeType, vi.proximityTown.placeName);

 

        sb.AppendFormat("\nDistance: {0} Direction: {1}  {2}, {3}  {4}  {5}  Type: {6} Name: {7}",

            vi.proximityCity.distance, vi.proximityCity.direction, vi.proximityCity.city, vi.proximityCity.state,

            vi.proximityCity.zip, vi.proximityCity.country, vi.proximityCity.placeType, vi.proximityCity.placeName);

                 

        lblVehicleInfo.Text = sb.ToString();

    }

    catch (Exception ex)

    {

        string sErrorMessage = DateTime.Now.ToString()

            " Exception during the getVehicleInformation call with error:\r\n"

            + ex.Message + "\r\n"

            + ex.StackTrace;

        lblVehicleInfo.Text = sErrorMessage;

    }

}

Build the Project and Run the Application

  • Was this article helpful?