-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathBasicRouteNotification.java
More file actions
47 lines (39 loc) · 1.87 KB
/
Copy pathBasicRouteNotification.java
File metadata and controls
47 lines (39 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.mapbox.samples;
import com.mapbox.api.directions.v5.DirectionsCriteria;
import com.mapbox.api.directions.v5.MapboxDirections;
import com.mapbox.api.directions.v5.models.DirectionsResponse;
import com.mapbox.api.directions.v5.models.Notification;
import com.mapbox.api.directions.v5.models.RouteOptions;
import com.mapbox.sample.BuildConfig;
import retrofit2.Response;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
public class BasicRouteNotification {
public static void main(String[] args) throws IOException {
simpleMapboxDirectionsRequest();
}
private static void simpleMapboxDirectionsRequest() throws IOException {
MapboxDirections.Builder builder = MapboxDirections.builder();
// 1. Pass in all the required information to get a simple directions route.
RouteOptions routeOptions = RouteOptions.builder()
.user("") // the user which has route notifications enabled
.profile(DirectionsCriteria.PROFILE_DRIVING_TRAFFIC)
.coordinates("-115.5747924943478,49.58740426100405;-115.33330133850265,49.444367698479994")
.steps(true)
.overview(DirectionsCriteria.OVERVIEW_FULL)
.geometries(DirectionsCriteria.GEOMETRY_POLYLINE6)
.excludeList(Arrays.asList(DirectionsCriteria.EXCLUDE_UNPAVED))
.build();
builder.routeOptions(routeOptions);
builder.accessToken(BuildConfig.MAPBOX_ACCESS_TOKEN);
// 2. That's it! Now execute the command and get the response.
Response<DirectionsResponse> response = builder.build().executeCall();
// 3. Log information from the response
System.out.println("Check that the GET response is successful " + response.isSuccessful());
if (response.isSuccessful()) {
List<Notification> notifications = response.body().routes().get(0).legs().get(0).notifications();
System.out.println("Notifications: " + notifications);
}
}
}