Get familiar with Sygic Fleet APIs by studying examples of Sample Codes
- Show the navigation inside a panel the in the application window or show the navigation inside a surface in the application
- Search for an address to get coordinates (exact or using Fuzzy search)
- Create route from one location to another and navigate along it
- Configure the navigation for 12t heavy truck, 3.5m wide and 3m tall
- Inform driver about important situation by displaying and speaking a message and wait for his confirmation
- Notify driver about exceeding a speed limit and show him actual information
/*
* We want to show the navigation inside a panel in the application window
*/
//import .dll library
using ApplicationAPI;
...
//declaration of needed variables
int embedded_height;
int embedded_width;
IntPtr embedded_handle;
Thread driveThread;
...
//get dimensions and handle of the panel the Drive will be embedded into
this.embedded_height = drive_Panel.Height;
this.embedded_width = drive_Panel.Width;
this.embedded_handle = drive_Panel.Handle;
//Drive needs to be run in a separate thread
driveThread = new Thread(new ThreadStart(this.startEmbeddedDrive));
driveThread.Start();
...
private void startEmbeddedDrive()
{
//starting Drive in the panel
CApplicationAPI.InitApi(@"C:\work\FLEET_XP_15c\Drive\WindowsXP\Drive.exe", null, 0, 0,
embedded_width, embedded_height, true, true, embedded_handle);
}
/*
* We want to show the navigation inside a surface in the application
*/
//import needed packages
import com.sygic.drive.SygicService;
import com.sygic.drive.api.DriveApi;
import com.sygic.drive.api.DriveCallback;
import com.sygic.drive.LocalBinder;
...
//declaration and definition of some needed variables
private SurfaceView mSurface;
private SygicService mService;
private DriveCallback mCallback;
private Handler mHandler = new Handler();
...
public void onCreate(Bundle savedInstanceState) {
...
//save reference to the surface so it can be used later...
mSurface = (SurfaceView) findViewById(R.id.surfaceView1);
mCallback = new DriveCallback() {
//run Drive
public void onRunDrive() {
mHandler.post(new Runnable() {
public void run() {
if (mService != null) {
mService.runDrive();
}
}
});
}
public void onInitApi() {
int status = DriveApi.initApi(getPackageName(), true);
//check if InitApi succeeded
if (status == 1) { /* do something */ }
else { /* do something */ }
...
}
...
}
...
}
...
//we implement a service connection which is used when binding to the service
private ServiceConnection mConnection = new ServiceConnection() {
// this is called asynchronously when a successful connection has been established
public void onServiceConnected(ComponentName className, IBinder service) {
mService = ((LocalBinder) service).getService();
if (mService != null) {
//we need to pass our surface reference, on which we want to
//draw, to the service, this can be called from anywhere
mService.setSurface(mSurface)
}
...
}
...
}
/*
* Create route from one location to another and navigate along it
*/
//import .dll library
using ApplicationAPI;
...
//declaration of SError variable which holds return value of API methods
SError err;
//definition of the name of itinerary which will be used
String itineraryName = "Business trip";
//Array of points that will form itinerary
SStopOffPoint[] points_array = new SStopOffPoint[2];
points_array[0] = new SStopOffPoint(new LONGPOSITION(234120, 4885693), "Company Site", 1);
points_array[0].nPointType = 3;
//nPointType 3 = Start point
points_array[1] = new SStopOffPoint(new LONGPOSITION(230225, 4887142), "Important Client", 1);
points_array[1].nPointType = 2;
//nPointType 2 = Finish point
...
//add itinerary API method
CApplicationAPI.AddItinerary(out err, points_array, itineraryName, 0);
...
//set route from the saved itinerary
CApplicationAPI.SetRoute(out err, itineraryName, 0, true, 0);
/*
* Configure the navigation for 12t heavy truck, 3.5m wide and 3m tall
*/
//import .dll library
using ApplicationAPI;
...
//declaration of SError variable which holds return value of API methods
SError err;
//struct for getting/setting options
SChangeOption truck_options = new SChangeOption();
//setting sample values in some of the truck fields. Please note that bUseTruckAtt value MUST be set to 1
//for navigation to take the other truck attributes into account.
truck_options.bUseTruckAtt = 1;
truck_options.nTruckWeightTotal = 12000;
truck_options.nTruckHeight = 3000;
truck_options.nTruckWidth = 3500;
...
//change of settings in the Drive (it also gets the current values of all fields)
CApplicationAPI.ChangeApplicationOptions(out err, ref truck_options, 0);
/*
* Inform driver about important situation by displaying and speaking a message
* and wait for his confirmation
*/
//import .dll library
using ApplicationAPI;
...
//declaration of SError variable which holds return value of API methods
SError err;
//user’s answer will be stored in variable value
int value = 0;
String textToDisplay = "Allowed driving time exceeded, you should take one hour rest.";
...
//API method that will read the text to the driver
CApplicationAPI.PlaySoundTTS(out err, textToDisplay, 0);
//Show message on the screen and wait for reply. The reason why reading the text is before actually showing it is
//that ShowMessage method will block following code until driver’s reply, which might not be immediate.
CApplicationAPI.ShowMessage(out err, textToDisplay, 3, true, true, ref value, 0);
...
if (value == 201) //driver’s answer was Yes
{ /* do something */ }
else if (value == 101) //driver’s answer was No
{ /* do something */ }
/*
* Notify driver about exceeding a speed limit and show him actual information
*/
//import .dll library
using ApplicationAPI;
...
//declaration of SError variable which holds return value of API methods
SError err;
//definition of Drive handler which will handle events raised by Drive
CApplicationAPI.ApplicationHandler Drive_handle = new CApplicationAPI.ApplicationHandler(DriveHandler.NavHandler);
//initialize API with handle and set route from itinerary to start navigating (if you have valid GPS signal)
CApplicationAPI.InitApi(@"C:\work\FLEET_XP_15c\Drive\WindowsXP\Drive.exe", Drive_handle, 0, 0, 400, 600);
CApplicationAPI.SetRoute(out err, "myItinerary", (int)NavigationParams.NpMessageRouteUnable, true, 0);
...
//separate class for handling events
public class DriveHandler
{
...
//navHandler method is invoked whenever an Event is raised by Drive
public static void NavHandler(int nEventID, IntPtr strData)
{
switch ((ApplicationEvents)nEventID)
{
//we want to handle the Event raised when driver exceeds the speed limit
case ApplicationEvents.EVENT_SPEED_EXCEEDING:
notifyDriverAboutSpeed();
break;
}
...
private static void notifyDriverAboutSpeed()
{
SError err;
//variable limit will hold current speed limit
int limit = 0;
//variable current_position is a struct which will hold (among other fields) driver’s current speed
SGpsPosition current_position;
//fill the variables with needed information
CApplicationAPI.GetActualGpsPosition(out err, out current_position, false, 0);
CApplicationAPI.GetCurrentSpeedLimit(out err, out limit, 0);
//display a message about exceeding speed limit
CApplicationAPI.FlashMessage(out err, "Speed limit " + limit + " exceeded! Your current speed is "
+ current_position.Speed + ". Speeding will be logged.", true, 0);
}
...
}