The core feature of the Sygic Android SDK is Maps. The key concepts covered in this section include adding a map to an Android application, changing the location displayed by the map and its various properties. The classes covered include MapFragment and MapView. The MapFragment is a standard Android Fragment derived component. You can create a controller class to coordinate all interactions using custom logic.

Once the MapFragment is initialized, you get the Map associated with the MapFragment through MapFragment.getMapView(). The MapView class represents the virtual model of the world in a digital format.

For example, the following code snippet illustrates how to render the Map at London, UK.

// get MapView
MapView map = mapFragment.getMapView();

// Set the map center to London, UK.
map.getCamera().setPosition(new GeoCoordinate(51.509865,-0.118092));

You do not see the roads, POIs, buildings etc? Yes, since the current version of the SDK works just with offline maps, you have to download them to see all these beautiful details. Please follow to Offline Maps section for more details!

In the preceding code the GeoCoordinate for the map center is created by a call to the new GeoCoordinate(double, double) constructor.

Map Handling

Once the MapView is initialized, it can be manipulated and interacted in a variety of ways. Some key attributes of the MapView are its orientation, tilt, geographical center (geoCenter), and zoom level (zoom). These attributes may be used to customize the MapView display.

Zoom Level
The size of the geographical area displayed by Map can be controlled by changing the zoom level.

// Set the zoom to for example 0.000124117648996820.
map.getCamera().setZoom(0.000124117648996820);

// Get the zoom level, should be 0.000124117648996820.
float zoom = map.getCamera().getZoom();

Rotation
The map can be orientated in any direction. By default, the rotation is in a true North position. The following code changes the orientation to South-up.

// Rotate 180 degrees.
map.getCamera().setRotation(180);

// Get the rotation, should be 180.
float rotation = map.getCamera().getRotation();

Tilt
The map can be tilted and rendered in a three-dimensional perspective. By default, the tilt is completely flat.

// Set the tilt to 45 degrees
map.getCamera().setTilt(45);

// Get the tilt
float tilt = map.getCamera().getTilt();
Tilt used to display 3D or 2D mode

Camera listeners

Sygic Mobile SDK enables to easily control your camera. You can simply add camera listeners this way:

map.getCamera().addModeChangedListener(new Camera.ModeChangedListener() {
    @Override
    public void onMovementModeChanged(final int mode) {
        if (mode == Camera.MovementMode.Free) {
            //do you stuff here
        }
    }

    @Override
    public void onRotationModeChanged(final int mode) {
        if (mode == Camera.RotationMode.Vehicle) {
            //do you stuff here
        }
    }
});

or

map.getCamera().addPositionChangedListener(new Camera.PositionChangedListener() {
    @Override
    public void onPositionChanged(final GeoCoordinates geoCenter, final float zoom, final float rotation, final float tilt) {
        //do you stuff here
    }
});

If you no longer need listeners (eg OnDestroy), don't forget to unregister the listeners as well:

map.getCamera().removeModeChangedListener(this);
map.getCamera().removePositionChangedListener(this);
...

Default map click handling

Click on map is handled internally by MapFragment and action on click depends on map object.
If you want to perform own action on click (like displaying context menu, bubble over map, etc...) you have to register MapGestureListener

MapView map = mapFragment.getMapView();
map.setMapGestureListener(new DefaultMapGestureListener(map) {
            @Override
            public boolean onMapMove(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
                // do something...
                return true;
            }
        });

This will override only onMapClick() method. Calling true as return value will prevent delagating onMapClick to SDK. Then you can get the tapped Map geocoordinates,

final MapView map = mapFragment.getMapView();
GeoCoordinates get = map.getCoordinatesFromPoint(x, y);

where {x, y} are coordinates of point inside of the MapFragment (obtained for example using MapFragment.OnClickListener or your own listener).

Map Schemes

There are some map schemes available to offer your application users a choice among different kinds of map appearance. Currently we support day and night skin.

map.setActiveSkin(MapView.MapSkin.Day); // or night
Day skin Night Skin

Sygic SDK does not automatically switch map schemes during navigation mode. Before starting car or pedestrian navigation, be sure to save the current map scheme and switch to the appropriate navigation map scheme.

Gestures

The MapView class responds to a number of predefined touch gestures. The default behavior of the map for each gesture type may be used as-is, supplemented, or replaced entirely. The following table is a summary of the available gestures and their default behavior.

Gesture Description Following gestures
Rotate Rotate: Two-finger press, simultaneously orbit both fingers around the center point, lift Pinch, Spread, Move
Zoom out Pinch: Two-finger press, move inwards, lift Spread, Rotate, Move
Zoom in Spread: Two-finger press, move outwards, lift
Move Swipe: One-finger press, move, lift/don't lift
Tilt Tilt: Two fingers press, move up (increase the tilt angle) or move down (decrease the tilt angle)
Short touch Short touch: One-finger press, lift 

Map input like map dragging, map rotation, map tilt, map zoom is handled internally by MapFragment. However you can override default behavior by setting your own listener

MapView map = mapFragment.getMapView();
map.setMapGestureListener(new DefaultMapGestureListener(map) {
            @Override
            public boolean onMapMove(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
                // do something...
                return true;
            }
        });

Set return value true if the listener has consumed the event, false otherwise. If is false, default gesture action will be executed.

Objects and Interaction

The Sygic Mobile SDK allows the addition of a variety of objects, each with a specific purpose, to a map view. The types of available object include map markers, routes, polylines, circles. To see all the objects check the MapObject API reference. Some objects are described in more detail below.

In order to display the map object on the map, the object needs to be added to an MapView by calling addMapObject:.Following example shows how to display MapCircle on a map.

MapCircle circle = new MapCircle();
mMap.addMapObject(circle);

// removing
mMap.removeMapObject(circle);

MapCircle
Enables you to draw a circle on the map at a fixed geographical location. You can customize you circle's color, radius, lineColor - see the SYMapCircle API reference for more information.

Circle

MapPolyline
Enables you can draw one or more connected line segments on the map. The segment vertices are specified by a series of GeoCoordinates. The visual appearance of the polyline can be customized. See the MapPolyline API reference for more information.

Polyline

MapMarker
With Sygic Mobile SDK you can display a icon at a fixed geographical position on the map.

You can choose from these icons types:

  • Start
  • Via
  • Finish
Marker

Each of these objects could be selected by either tapping on the map.

Offline Maps

Applications developed with the Sygic Android SDK have the ability to pre-load map data, allowing the use of maps, search, routing, and other features without an active data connection. To download any map, special map id must be obtained, via listing of continents and maps for continent.

mMapDownload = new MapDownload();
mMapDownload.loadContinents();

List of continent is returned via MapListListener. From this list is obtained id for getting list of maps

mMapDownload.loadMapList(continent.getId());

Now you have to add map list listener

mMapListListener = new MapListListener() {
    @Override
    public void onContinentList(ContinentEntry[] continents, int result) {
    }

    @Override
    public void onMapList(MapEntry[] maps, int result) {
    }
};

mMapDownload = new MapDownload();
mMapDownload.addMapDownloadListener(mMapListListener);

Map installation
Installing or uninstalling maps is done using id obtained from list of map returned via MapListListener.

mMapDownload.installMap(map.getId());

Now you have to add map install listener.

mMapInstallListener = new MapInstallListener() {
    @Override
    public void onMapInstallProgress(String id, long bytesDownloaded, long totalBytes) {
    }

    @Override
    public void onMapInstallFinished(MapEntry entry, int result) {
    }

    @Override
    public void onMapUninstallFinished(MapEntry entry, int result) {
    }
};

mMapDownload.addMapInstallationListener(mMapInstallListener);

If you want to remove map listener, you can do it like this:

mMapDownload.removeMapDownloadListener(mMapListListener);