Click or drag to resize
Marker Import
Print this page

At the end of this tutorial, you will have a simple Windows console application that lets you import circle markers from a CSV file into Fleet.

Each line of the CSV file should have this format: latitude,longitude,tag,radius

Tip Tip

The radius property describes the size of the circle marker in feet. Fleet uses this radius value to determine whether points are located at a marker. For example, a typical truckstop marker may have a radius of several hundred feet, which ensures that trucks parked adjacent are identified as being at the truckstop.

This topic contains the following sections:

Creating the project

Open Visual Studio and create a new C# or VB.NET Windows Console application. Name the project 'MarkerImport'.

Adding the web service

In Visual Studio, ensure that your project has a reference to the Fleet Web Service API:

  1. In Solution Explorer, right-click your project and select Add Service Reference... (.NET 2: then click Advanced (at lower left), and click Add Web Reference).
  2. For the Address (.NET 2: API URL), enter https://<customer>.api.telogis.com/V2/<customer>/wsdl, where <customer> is your account name.
  3. Click Go.
  4. Change the Namespace (.NET 2: Web reference name) to Fleet, then click OK.
    tutorial-createproject-selectservice 4
Connecting to Fleet

Add the following code snippet to the Main function. This snippet simply authenticates with Fleet and prepares the LegacyClientService for subsequent Fleet requests.

.NET 4

// Connect to Fleet
Console.WriteLine("Connecting to Fleet...");
System.Net.ServicePointManager.Expect100Continue = false;

// Create a TelogisServiceClient for logging in
Fleet.TelogisServiceClient tsclient = new Fleet.TelogisServiceClient();

// Log in and obtain an authentication token
string authToken=tsclient.Login(String.Format("{0}:{1}", customer, user), pword);

// Now create the LegacyTelogisServiceClient for accessing the API
Fleet.LegacyTelogisServiceClient service = new Fleet.LegacyTelogisServiceClient();
Fleet.AuthenticationHeader header = new Fleet.AuthenticationHeader();
header.SessionID = authToken;
Creating a Category

Category objects are a collection of Marker objects. For best results, you should use categories to group markers. In this project we'll create a new category (with a name similar to "Import 7/1/2012"). We will then import all our markers into this category.

Add the following code snippet to the Main function.

.NET 4

// Add a new Category
String categoryTag = "Import " + DateTime.Today.ToString().Split(' ')[0];
long categoryId = service.CreateCategory(header, categoryTag, null);
Console.WriteLine("Created category \"{0}\"", categoryTag);
Reading input and exporting to Fleet

Add the following code snippet to the Main function. This snippet opens a file (specified by the first command-line argument) and reads the contents line-by-line. Each line is split into values separated by commas. These values are converted where necessary and then used to create a new marker. Important points to note are:

  • The CreateCategory method returned the ID number of the newly created category. Using this ID when we create a marker, we can place each marker into our newly created category.

  • Each marker is created without an address, driver and properties. This is done by setting each argument to null (Nothing)or zero, as appropriate.

.NET 4

// Read input from the specified file. The line format is:
// 
//    [lat.itude],[lon.gitude],[tag],[radius]
// 
// Values are then ripped from the input and turned into a
// marker immediately (using the Fleet Web Service).

Console.Write("Importing markers from file");
StreamReader sr = new StreamReader(args[0]);
String currentLine;
Fleet.LatLon location = new MarkerImport.Fleet.LatLon();

while ((currentLine = sr.ReadLine()) != null) {
// output a '.' for each marker imported
Console.Write(".");

// split the line around commas, and rip out the values required
String[] lineValues = currentLine.Split(',');
location.Latitude = Convert.ToDouble(lineValues[0]);
location.Longitude = Convert.ToDouble(lineValues[1]);
String tag = lineValues[2];
int radius = Convert.ToInt32(lineValues[3]);

// create the new Marker using the Fleet Web Service
service.CreateMarker(header, tag, location, null, radius, categoryId, 0, null);
}

sr.Close();
Console.Write("\nAll done! Press a key to exit");
Console.ReadKey();

That completes the Marker Import sample project. The next sample project demonstrates how to list exceptions and associated information.