Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.
Jan Skrasek edited this page Feb 22, 2018 · 14 revisions

Sygic Travel SDK provides access to Sygic Travel API & data. The whole Sdk is divided into separate modules. The modules as partially connected, but you may use only some of them. Sdk provides the following modules:

For further details see SDK Reference Documentation. You may also check the JSON API Documentation.

Installation

First, add an implementation dependency to your build.gradle file. Check the releases for the latest version.

dependencies {
	implementation 'com.sygic.travel:sdk:2.0.0-beta-1'
}

Sdk artifacts are available on jCenter, add jcenter() to your repositories.

Initialize an Sdk instance in your dependency injection container or directly in your Application. You have to obtain an API key and a Client Id, contact us at https://travel.sygic.com/b2b/api-key. In case you want to use only Places module the API key is sufficient. Most of the modules require also the Client Id, see the specific modules.

val sdk = Sdk(
	applicationContext,
	object : SdkConfig() {
		override val apiKey
			get() = "your-api-key"
		override val clientId
			get() = "your-client-id"
	}
)

Usage

All Sdk calls are synchronous and must be called from a background thread.

To ease the implementation, you may use any tool you like/already use in your application. The best approach is use Kotlin language and coroutines; though, SDK can be of course used from Java as showed in the following examples with Rx Java. We provide two basic examples for the start, the all other examples use Kotlin only.

Kotlin example:

suspend fun getPlaces(): List<Place> {
	async {
		val placesQuery = PlacesQuery()
		placesQuery.levels = listOf(Level.POI)
		placesQuery.categories = listOf(Category.SIGHTSEEING)
		placesQuery.parentIds = listof("city:1")
		placesQuery.limit = 10

		sdk.placesFacade.getPlaces(placeQuery)
	}.await()
}

Java & RxJava example:

Single.fromCallable(new Callable<List<Place>>() {
		@Override
		public List<PlaceInfo> call() throws Exception {
			PlacesQuery placeQuery = new PlacesQuery();
			placeQuery.setLevels(Collections.singletonList(Level.POI));
			placeQuery.setCategories(Collections.singletonList(Category.SIGHTSEEING));
			placeQuery.setParentIds(Collections.singletonList("city:1"));
			placeQuery.setLimit(10);

			return sdk.getPlacesFacade().getPlaces(placeQuery);
		}
	})
	.subscribeOn(Schedulers.io())
	.observeOn(AndroidSchedulers.mainThread())
	.subscribe(new Consumer<List<Place>>() {
		@Override
		public void accept(List<Place> places) throws Exception {
			// do something with fetched places
		}
	});

Error handling

Errors are propagated as exceptions, the best is way is to try/catch for runtime exceptions.

Clone this wiki locally