-
Notifications
You must be signed in to change notification settings - Fork 1
Home
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:
- Places module: provides an interface for places searching, fetching places lists & details, fetching place's media;
- Session module: allows managing a session for handling user data;
- Trips module: provides interface for creating & managing user trips;
- Favorites module: manages user favorite places;
- Synchronization module: allows server synchronization of user data;
- Directions module: interface for fetching navigation data between places;
- Events module: central place for Sdk's internal events handling;
- Tours module: provides an interface for tours searching, fetching tours lists;
For further details see SDK Reference Documentation. You may also check the JSON API Documentation.
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"
}
)
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.parents = 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.setParents(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
}
});
Errors are propagated as exceptions, the best is way is to try/catch for runtime exceptions.