System Requirements

  • Android 4.1 "Jelly Bean" (API Level 16) or higher
  • Android Studio 3.0 or above (building with earlier version might be possible, but is not tested, nor supported)
  • Mass storage is required for persistent storage of map data. At a minimum, 50MB of free space is required to be available for map data

Install the SDK

Add repository into your project build.gradle file

repositories {
    maven {
        url "https://sdk-repo.sygic.com/NAVI-SDK-stage/"
    }
}

Add dependency into you application build.gradle file. Note the @aar part, it is necessary to correctly use th SDK. See the Release Notes for latest version.

dependencies {
    implementation("com.sygic.sdk:sdk-release:$sygicSdkVersion@aar") {
        transitive true
    }
}

android {
    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }
}

Initialize the SDK

The first step to integrate Sygic SDK is to initialize SygicEngine. This has to happen before using any other part of SDK. A good place for this is custom Application class.

package com.sygic.sdk.gettingstarted;

import android.app.Application;

import com.sygic.sdk.SygicEngine;

public class CustomApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        new SygicEngine.Builder(Credentials.API_KEY, Credentials.SECRET_CODE, this)
                .setInitListener(new SygicEngine.OnInitListener() {
                    @Override
                    public void onSdkInitialized() {
                        // now you are ready to use sdk
                    }

                    @Override
                    public void onError(@InitError int error) {}
                }).init();
    }
}

To integrate a map into an application is to insert a MapFragment to the view layout of the application. You can do this by adding MapFragment to the layout xml as follows.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <fragment
        android:id="@+id/mapFragment"
        class="com.sygic.sdk.map.MapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</LinearLayout>

Alternatively, you can add MapFragment to your Activity in code.

FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

MapFragment fragment = new MapFragment();
fragmentTransaction.add(R.id.fragment_container, fragment);
fragmentTransaction.commit();

After adding the MapFragment to the layout, the fragment must be initialized. The MapFragment initialization is processed asynchronously. During initialization, the map engine is initialized to create an instance of MapView that is associated with the MapFragment.

The following code illustrates the basic initialization flow when an Activity is created. Replace API_KEY with your API key and SECRET_CODE with your secret code. The enableOnlineMapStreaming(true) call enables online maps. To display map offline, see Offline Maps

package com.sygic.sdk.gettingstarted;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import com.sygic.sdk.map.MapFragment;
import com.sygic.sdk.map.MapView;
import com.sygic.sdk.map.listeners.OnMapInitListener;
import com.sygic.sdk.online.OnlineManager;

public class MapActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final MapFragment mapFragment = (MapFragment) getSupportFragmentManager().findFragmentById(R.id.mapFragment);

        // getMapAsync() will internally wait for engine initialization
        mapFragment.getMapAsync(new OnMapInitListener() {
            @Override
            public void onMapReady(MapView mapView) {
                // Now you can start work with the ready mapView object
                OnlineManager.getInstance().enableOnlineMapStreaming(true);
            }

            @Override
            public void onMapError(int error, String info) {}
        });
    }
}

Release Notes