Navigation Warnings

The Sygic Android SDK supports navigation on pedestrian and car routes. Using this feature, your app can check the current device position against a calculated route and provide just-in-time navigational instructions, both as visual and voice instructions. Turn-by-Turn Navigation Mode, which takes the calculated route and matches the current position against the route is supported for walking and driving.

While navigating, application can register a listener for warning notifications and display all of these notifications. All the types of notifications are listed in NavigationManager class. The following table shows the name of the available listeners and the information provided by them.

Listener name Function
OnBetterRouteListener Whether a faster route has been found
OnDirectionListener Whether the direction has chnaged
OnSpeedLimitListener Whether the user has exceeded the speed limit
OnSignpostListener Whether the signpost has updated
OnLaneListener Whether the lane information has changed
OnPlaceListener Whether the nearby place info has changed
OnIncidentListener Whether and icident is ahead
OnRailwayCrossingListener Whether a railway crossing is ahead
OnHighwayExitListener Whether a highway exit is ahead
OnSharpCurveListener Whether a sharp curve is ahead
OnWaypointPassListener Whether the vehicle passed by a waipoint
OnTrafficChangedListener Whether the traffic data has updated
OnRouteChangedListener Whether the route has changed
OnRecomputeProgressListener Whether the route recompute progress has changed (100 is the max value)

Registering a listener has the following pattern:

// create listener
mOnSpeedLimitListener = new NavigationManager.OnSpeedLimitListener() {
    @Override
    public void onSpeedLimitInfoChanged(@NonNull SpeedLimitInfo speedLimitInfo) {
        // info about changed value
        Log.d("TAG", "SpeedLimit: " + speedLimitInfo.getSpeedLimit());
        Log.d("TAG", "NextSpeedLimit: " + speedLimitInfo.getNextSpeedLimit());
        // ...
    }
};

// register the listener
NavigationManagerProvider.getInstance(new InitializationCallback<NavigationManager>() {
    @Override
    public void onInstance(@NonNull NavigationManager navigationManager) {
        navigationManager.addOnSpeedLimitListener(mOnSpeedLimitListener);
    }
    @Override
    public void onError(int i) {
    }
}); 

Don't forget to unregister the listener when you don't need it.

navigationManager.removeOnSpeedLimitListener(mOnSpeedLimitListener);

Map Matching During Navigation

Map Matching is automatically enabled in both navigation mode and tracking mode. In simulation mode, the map-matched position is simulated along the route with a user-defined speed.

Handling route changes when you steer away from the route

When you leave the route that you have chosen for navigation, the SDK handles the recompute internally and sets the new route for navigation as well. All you need to do is to remove the old MapRoute and add a new one, using the route that you get in the onRouteChanged listener callback.

Voice Instructions

Voice instructions are available in the Sygic SDK as voice packages. Voice packages are available in two forms: pre-packaged or downloadable through the voice catalog. You can set a voice package to be used for navigational instructions.

The Sygic SDK supports two types of voice packages: text-to-speech or pre-recorded. Pre-recorded voice skins provide basic maneuver instructions, such as "turn right in 100 meters", while text-to-speech voices also support spoken street names, such as "turn right in 100 meters onto Wall Street".

Following code shows, how to get the list of installed voices and setting the voice:

VoiceManager.getInstance().getInstalledVoices(new VoiceManager.InstalledVoicesCallback() {
    @Override
    public void onInstalledVoiceList(final VoiceEntry[] voices, @NonNull final OperationStatus status) {
        VoiceManager.getInstance().setVoice(voices[0]);
    }
});

To get all available voices, you call VoiceDownload.getAvailableVoices():

VoiceDownload voiceDownload = new VoiceDownload();
voiceDownload.getAvailableVoiceList(new VoiceDownload.AvailableVoicesCallback() {
    @Override
    public void onAvailableVoiceList(final VoiceEntry[] voiceEntries, @NonNull final OperationStatus operationStatus) {
        for (final VoiceEntry entry : voiceEntries) {
            String name = entry.getName();
            String language = entry.getLanguage();
            boolean tts = entry.isTts();
            switch (entry.getStatus()) {
                case VoiceEntry.VoicePackageStatus.NotInstalled:
                    //...
                    break;
                case VoiceEntry.VoicePackageStatus.Installed:
                    //...
                    break;
                default:
                    //...
            }
        }
    }
});

Then you can download voices.

 voiceDownload.addVoiceInstallationListener(new VoiceInstallListener() {
     @Override
     public void onVoiceInstallProgress(VoiceEntry voice, long bytesDownloaded, long totalBytes) {

     }

     @Override
     public void onVoiceInstallFinished(final VoiceEntry voice, @NonNull final OperationStatus status) {

     }

     @Override
     public void onVoiceUninstallFinished(final VoiceEntry voice, @NonNull final OperationStatus status) {

     }
});

 voiceDownload.installVoice(voice); // entry is an object returned in onAvailableVoiceList

You can register an AudioInstructionListener in which you can either tell our SDK to play the instruction (returning false from the method, like below) or play any information from the direction info however you want.

mNavigationManager.setAudioInstructionListener(new NavigationManager.AudioInstructionListener() {
    @Override
    public boolean onAudioInstruction(DirectionInfo directionInfo) {
        return false;
    }
});

This is a list of the potential TTS languages that are supported. Actual audio playback depends on the supported languages in the user's installed version of Android.

  • English (US)
  • English (UK)
  • French (France)
  • French (Canada)
  • German
  • Spanish (Spain)
  • Spanish (Mexico)
  • Indonesian
  • Italian
  • Norwegian
  • Portugese (Portugal)
  • Portugese (Brazil)
  • Russian
  • Swedish
  • Finnish
  • Danish
  • Korean
  • Chinese (Taiwanese Mandarin)
  • Turkish
  • Czech
  • Polish

Traffic

Traffic information show traffic incidents on the map. Traffic visualization requires a network data connection to download real time traffic information. However, traffic information may continue to be displayed thereafter without a connection until the traffic events expire or the visibility is toggled.

Traffic information

Signposts

Signs represent textual and graphic information which are along the route. The information is always represented as text or pictogram. Signpost information may be used for route guidance and map display. A navigation system may prefer using the signpost text rather than the street/ramp name as the latter may not always match what is on the sign in reality and may confuse a user. The signpost feature supports the user navigating through complex situations and provides a conformation for a maneuver by presenting the same direction information as shown on the street signs in reality.

Based on the map attributes, the Sygic Android Mobile SDKs aggregate the following information into a Signpost object:

  • Route number
  • Exit number
  • Exit name
  • Pictogram
  • Place name
  • Background color
  • Text color

Following example shows, how to get these information from the data structure, which the Android SDK offers.

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;

import com.sygic.sdk.navigation.NavigationManager;
import com.sygic.sdk.navigation.routeeventnotifications.SignpostInfo;

import java.util.ArrayList;
import java.util.List;

public class SignpostFragment extends Fragment implements NavigationManager.OnSignpostListener {

    private NavigationManager mManager;

    @Override
    public void onCreate(@Nullable final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        NavigationManagerProvider.getInstance(new InitializationCallback<NavigationManager>() {
            @Override
            public void onInstance(@NonNull NavigationManager navigationManager) {
                mManager = navigationManager;
            }
            @Override
            public void onError(int i) {
            }
        });
        mManager.addOnSignpostListener(this);
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
        mManager.removeOnSignpostListener(this);
    }

    // ....

    @Override
    public void onSignpostChanged(@NonNull List<SignpostInfo> list) {
        if (list.isEmpty()) {
            return;
        }

        final SignpostInfo signpostInfo = list.get(0);
        final int textColor = signpostInfo.getTextColor();
        final int backgroundColor = signpostInfo.getBackgroundColor();
        final int distanceToSignpost = signpostInfo.getDistance();

        final List<String> titles = new ArrayList<>();
        final List<String> roadNumbers = new ArrayList<>();
        final List<String> exits = new ArrayList<>();
        final List<String> exitNumbers = new ArrayList<>();

        for (SignpostInfo.SignElement signElement : signpostInfo.getSignElements()) {
            switch (signElement.getElementType()) {
                case SignpostInfo.SignElement.SignElementType.PlaceName:
                case SignpostInfo.SignElement.SignElementType.StreetName:
                case SignpostInfo.SignElement.SignElementType.OtherDestination:
                    titles.add(signElement.getText());
                    break;
                case SignpostInfo.SignElement.SignElementType.RouteNumber:
                    roadNumbers.add(signElement.getText());
                    break;
                case SignpostInfo.SignElement.SignElementType.ExitName:
                    exits.add(signElement.getText());
                    break;
                case SignpostInfo.SignElement.SignElementType.ExitNumber:
                    exitNumbers.add(signElement.getText());
                    break;
            }
        }

        // do something with the collected data
    }
}

Directions

To provide more detailed information in signpost, you can display the direction which the user should follow. The Directions feature allows developers to define and display routes between a start and a destination point within their application. NavigationManager.OnDirectionListener can return the following information:

  • Direction distance
  • Next direction distance
  • Maneuver type - see the all available ManeuverTypes
  • Current and next road names
  • Current and next road numbers
  • Whether you are in a tunnel and the remaining distance to its end

The following example shows how to get these information from the data structure, which the Android SDK offers.

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;

import com.sygic.sdk.navigation.NavigationManager;
import com.sygic.sdk.navigation.routeeventnotifications.DirectionInfo;
import com.sygic.sdk.route.RouteManeuver;

public class DirectionFragment extends Fragment implements NavigationManager.OnDirectionListener {

    private NavigationManager mManager;

    @Override
    public void onCreate(@Nullable final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        NavigationManagerProvider.getInstance(new InitializationCallback<NavigationManager>() {
            @Override
            public void onInstance(@NonNull NavigationManager navigationManager) {
                mManager = navigationManager;
            }
            @Override
            public void onError(int i) {
            }
        });
        mManager.addOnDirectionListener(this);
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
        mManager.removeOnDirectionListener(this);
    }

    // ....

    @Override
    public void onDirectionInfoChanged(@NonNull final DirectionInfo directionInfo) {
        final int distance = directionInfo.getDistance();
        final int nextDistance = directionInfo.getNextDistance();

        final RouteManeuver primaryManeuver = directionInfo.getPrimary();
        if (primaryManeuver != null) {
            final int type = primaryManeuver.getType();
            final String roadName = primaryManeuver.getRoadName();
            final String nextRoadName = primaryManeuver.getNextRoadName();
            final List<String> nextRoadNumbers = primaryManeuver.getNextRoadNumbers();
            Log.d("directions", "direction of type " + type + " on the road " + roadName + ". Next road is " + nextRoadName);
        }

    }
}

With these data now you just have to draw them into your view and create your own signposts. For example like this:

Signpost

Junction Info

Junction info is one of our advanced safety features. When you are approaching a complex highway intersection, a SingpostJunctionInfo object will be set in a OnSignpostListener. It contains info about lanes both continuing on highway and on the exit. You can then display this information, eg. as full screen diagram.

mNaviSignListener = new NavigationManager.OnSignpostListener() {
    @Override
    public void onSignpostChanged(@NonNull final List<SignpostInfo> list) {
        for (final SignpostInfo signpostInfo : list) {
            SignpostJunctionInfo junctionInfo = signpostInfo.getJunctionInfo();

            if (junctionInfo.getAreaType() != SignpostJunctionInfo.AreaType.Unknown) {
                @SignpostJunctionInfo.TurnDirection int turnDirection = junctionInfo.getTurnDirection();
                @SignpostJunctionInfo.TurnType int turnType = junctionInfo.getTurnType();
                int fromLanes = junctionInfo.getFromLanesCount();
                int leftLanes = junctionInfo.getToLeftLanesCount();
                int rightLanes = junctionInfo.getToRightLanesCount();

                // display junction info

                return;
            }
        }

        // no junction info
    }
};

When you have SignpostJunctionInfo with getFromLanesCount() == 5, getToLeftLanesCount() == 4, getToRightLanesCount() == 2, it can be displayed as shown below.

Junction

Speed Limit

Speed limits indicate the legal speed for a vehicle. You can get the value either in mph or in km/h. You can register OnSpeedLimitListener to receive events about speed limit change. The class containing information about speed limit is SpeedLimitInfo.

mSpeedLimitListener = new NavigationManager.OnSpeedLimitListener() {

    @Override
    public void onSpeedLimitInfoChanged(@NonNull final SpeedLimitInfo speedLimitInfo) {
        int speedLimit = speedLimitInfo.getSpeedLimit(SpeedLimitInfo.SpeedUnits.Kilometers);
        int currentSpeed = speedLimitInfo.getCurrentSpeed(SpeedLimitInfo.SpeedUnits.Kilometers);

        if (speedLimit < currentSpeed) {
            // vehicle is speeding
        }

        int nextSpeedLimit = speedLimitInfo.getNextSpeedLimit(SpeedLimitInfo.SpeedUnits.Kilometers);
        int distance = speedLimitInfo.getNextSpeedLimitDistance();

        if (speedLimit != nextSpeedLimit) {
            // eg. show warning about limit change
        }

        @SpeedLimitInfo.SpeedUnits int countrySpeedUnits = speedLimitInfo.getCountrySpeedUnits();
        int naturalLimit = speedLimitInfo.getSpeedLimit(countrySpeedUnits);

        // natural limit is in country's natural units, so rounding and decimals can be avoided
    }
};

Route Simulation

You can quickly start a route simulation by requesting an instance of RouteDemonstrateSimulator and passing it the computed route:
Do not forget to call .stop() upon cancelling the route or if you no longer need the simulation to prevent unwanted behavior.
Also please note that you need to call the navigationManager's setRouteForNavigation before starting the simulator.

RouteDemonstrateSimulatorProvider.getInstance(mRoute, new InitializationCallback<RouteDemonstrateSimulator>() {
    @Override
    public void onInstance(@NonNull RouteDemonstrateSimulator routeDemonstrateSimulator) {
        routeDemonstrateSimulator.start();
    }

    @Override
    public void onError(int i) {
    }
});