System Requirements

  • Android 4.2 "Jelly Bean" (API Level 17) or higher
  • Android Studio 3.4 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

Note: The tutorial is suitable for SDK Version 18
Add the maven repository into your project's build.gradle file

repositories {
    maven {
        url "https://public.repo.sygic.com/repository/maven-sygic-releases/"
    }
}

Add the following dependency into your application's build.gradle file. Note the @aar part, it is necessary to correctly use the SDK version. See the Release notes for latest version. You can define the sygicSdkVersion variable in the ext part of your project's build.gradle file, or you can replace it directly.

dependencies {
    implementation("com.sygic.sdk:maps-android:$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 the SygicEngine. This has to happen before using any other part of SDK. A good place for this is a custom Application class.
It's necessary to pass the JSON configuration as a string. You can either create it yourself or use the JsonConfigBuilder, which is available since version 17. You can read more here. The clientID and path configuration items are necessary for proper configuration.

Optional: if you would like to receive logs from the SDK in your application, pass a LogConnector object into the .initialize method just like below:

SygicEngine sygicEngine;

public class CustomApplication extends Application {

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

       SygicEngine.JsonConfigBuilder config = new SygicEngine.JsonConfigBuilder();
       config.authentication("YOUR_SDK_CLIENT_ID");
       String path = Objects.requireNonNull(getApplicationContext().getExternalFilesDir(null)).toString(); //default Android/data/
       config.storageFolders().rootPath(path);

       sygicEngine.initialize(this, tracking: null, new LogConnector() {
            @Override
            public void onLogReceived(String message, int logLevel) {
                super.onLogReceived(message, logLevel);
             }
       }, config.build(), new SygicEngine.OnInitCallback() {
            @Override
            public void onInstance(@NonNull SygicContext sygicContext) {
                //your code
            }

            @Override
            public void onError(@NonNull CoreInitException e) {
                //handle the error
            }
       });
    }
}

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"></fragment>
</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. The onlineManager.enableOnlineMapStreaming() call enables online maps.
You should always wait for the success callback from the MapStreamingListener before doing simple operations such as calculating a route!
To ensure that the online maps are enabled during the initialization, you can add the following code to your configuration: config.mapReaderSettings().startupOnlineMapsEnabled(true), or to the appropriate field in the JSON if you use it.
To display offline maps, 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 onMapInitializationInterrupted() {}

            @Override
            public void onMapReady(@NonNull MapView mapView) {
                // Now you can start work with the ready mapView object
                OnlineManagerProvider.getInstance(new CoreInitCallback<OnlineManager>() {
                            @Override
                            public void onInstance(@NonNull OnlineManager onlineManager) {
                                onlineManager.enableOnlineMapStreaming(new OnlineManager.MapStreamingListener() {
                                    @Override
                                    public void onSuccess() {
                                    }

                                    @Override
                                    public void onError(OnlineManager.MapStreamingError mapStreamingError) {
                                    }
                                });
                            }

                            @Override
                            public void onError(@NonNull CoreInitException e) {
                            }
                        });
            }
    }
}