Loading...
Searching...
No Matches
NavigineSdkExample.java
Go to the documentation of this file.
1package com.navigine.examples;
2
3import com.navigine.idl.java.*;
4
5import java.util.ArrayList;
6import java.util.Collections;
7import java.util.List;
8
13public class NavigineSdkExample {
14
15 private NavigineSdk sdk;
16 private LocationManager locationManager;
17 private NavigationManager navigationManager;
18 private ZoneManager zoneManager;
19 private RouteManager routeManager;
20 private AsyncRouteManager asyncRouteManager;
21 private NotificationManager notificationManager;
22 private MeasurementManager measurementManager;
23 private LocationListManager locationListManager;
24 private StorageManager storageManager;
25 private MqttSession mqttSession;
26 private LocationWindow locationWindow;
27 private RouteLayer routeLayer;
28 private GuidanceCamera guidanceCamera;
29
31 initializeSdk();
32 }
33
37 private void initializeSdk() {
38 try {
39 // [java_NavigineSdk_getInstance]
40 // Get SDK instance
42 // [java_NavigineSdk_getInstance]
43
44 // [java_NavigineSdk_getVersion]
45 // Get SDK version
46 System.out.println("Navigine SDK Version: " + NavigineSdk.getVersion());
47 // [java_NavigineSdk_getVersion]
48
49 // [java_NavigineSdk_getDeviceId]
50 // Get device ID
51 System.out.println("Device ID: " + NavigineSdk.getDeviceId());
52 // [java_NavigineSdk_getDeviceId]
53
54 // [java_NavigineSdk_getRelativeTime]
55 // Get relative time
56 System.out.println("Relative Time: " + NavigineSdk.getRelativeTime());
57 // [java_NavigineSdk_getRelativeTime]
58
59 // [java_NavigineSdk_setUserHash]
60 // Set user hash (authorization token)
61 sdk.setUserHash("XXXX-XXXX-XXXX-XXXX");
62 // [java_NavigineSdk_setUserHash]
63
64
65 // [java_NavigineSdk_getUserAgent]
66 System.out.println("User-Agent: " + NavigineSdk.getUserAgent());
67 // [java_NavigineSdk_getUserAgent]
68
69 // [java_NavigineSdk_reset]
70 sdk.reset();
71 System.out.println("SDK reset to initial state");
72 // [java_NavigineSdk_reset]
73
74 // [java_NavigineSdk_setServer]
75 // Set server URL (optional)
76 sdk.setServer("https://custom.navigine.com");
77 // [java_NavigineSdk_setServer]
78
79 // Initialize managers
80 initializeManagers();
81
82 } catch (Exception e) {
83 System.err.println("SDK initialization error: " + e.getMessage());
84 }
85 }
86
90 private void initializeManagers() {
91 // [java_NavigineSdk_getLocationManager]
92 // Get LocationManager for working with locations
93 locationManager = sdk.getLocationManager();
94 if (locationManager != null) {
95 System.out.println("LocationManager successfully initialized");
96 }
97 // [java_NavigineSdk_getLocationManager]
98
99 // [java_NavigineSdk_getNavigationManager]
100 // Get NavigationManager for navigation
101 if (locationManager != null) {
102 navigationManager = sdk.getNavigationManager(locationManager);
103 if (navigationManager != null) {
104 System.out.println("NavigationManager successfully initialized");
105 }
106 }
107 // [java_NavigineSdk_getNavigationManager]
108
109 // [java_NavigineSdk_getZoneManager]
110 // Get ZoneManager for working with zones
111 if (navigationManager != null) {
112 zoneManager = sdk.getZoneManager(navigationManager);
113 if (zoneManager != null) {
114 System.out.println("ZoneManager successfully initialized");
115 }
116 }
117 // [java_NavigineSdk_getZoneManager]
118
119 // [java_NavigineSdk_getRouteManager]
120 // Get RouteManager for building routes
121 if (locationManager != null && navigationManager != null) {
122 routeManager = sdk.getRouteManager(locationManager, navigationManager);
123 if (routeManager != null) {
124 System.out.println("RouteManager successfully initialized");
125 }
126 }
127 // [java_NavigineSdk_getRouteManager]
128
129 // [java_NavigineSdk_getAsyncRouteManager]
130 // Get AsyncRouteManager for async route operations
131 if (locationManager != null && navigationManager != null) {
132 asyncRouteManager = sdk.getAsyncRouteManager(locationManager, navigationManager);
133 if (asyncRouteManager != null) {
134 System.out.println("AsyncRouteManager successfully initialized");
135 }
136 }
137 // [java_NavigineSdk_getAsyncRouteManager]
138
139 // [java_NavigineSdk_getNotificationManager]
140 // Get NotificationManager for notifications
141 if (locationManager != null) {
142 notificationManager = sdk.getNotificationManager(locationManager);
143 if (notificationManager != null) {
144 System.out.println("NotificationManager successfully initialized");
145 }
146 }
147 // [java_NavigineSdk_getNotificationManager]
148
149 // [java_NavigineSdk_getMeasurementManager]
150 // Get MeasurementManager for measurements
151 if (locationManager != null) {
152 measurementManager = sdk.getMeasurementManager(locationManager);
153 if (measurementManager != null) {
154 System.out.println("MeasurementManager successfully initialized");
155 }
156 }
157 // [java_NavigineSdk_getMeasurementManager]
158
159 // [java_NavigineSdk_getLocationListManager]
160 // Get LocationListManager for location list operations
161 locationListManager = sdk.getLocationListManager();
162 if (locationListManager != null) {
163 System.out.println("LocationListManager successfully initialized");
164 }
165 // [java_NavigineSdk_getLocationListManager]
166
167 // [java_NavigineSdk_getStorageManager]
168 // Get StorageManager for working with storages
169 storageManager = sdk.getStorageManager();
170 if (storageManager != null) {
171 System.out.println("StorageManager successfully initialized");
172 }
173 // [java_NavigineSdk_getStorageManager]
174
175 // [java_NavigineSdk_getRouteLayer]
176 // Create RouteLayer for building and drawing routes on the map
177 if (locationWindow != null) {
178 routeLayer = sdk.getRouteLayer(locationWindow);
179 if (routeLayer != null) {
180 System.out.println("RouteLayer successfully initialized");
181 }
182 }
183 // [java_NavigineSdk_getRouteLayer]
184
185 // [java_NavigineSdk_getGuidanceCamera]
186 if (locationWindow != null && routeLayer != null) {
187 guidanceCamera = sdk.getGuidanceCamera(locationWindow, routeLayer);
188 // [java_GuidanceCamera_setMode]
189 guidanceCamera.setMode(GuidanceCameraMode.FOLLOWING);
190 // [java_GuidanceCamera_setMode]
191 // [java_GuidanceCamera_set2DMode]
192 guidanceCamera.set2DMode(false);
193 // [java_GuidanceCamera_set2DMode]
194 // [java_GuidanceCamera_mode]
195 System.out.println("Guidance mode: " + guidanceCamera.mode());
196 // [java_GuidanceCamera_mode]
197 // [java_GuidanceCamera_instruction]
198 RouteInstruction next = guidanceCamera.instruction();
199 if (next != null) {
200 System.out.println("Next instruction: " + next.getTitle() + " " + next.getDistance() + " m");
201 }
202 // [java_GuidanceCamera_instruction]
203 // [java_GuidanceCamera_addListener]
204 guidanceCamera.addListener(new GuidanceListener() {
205 @Override
206 public void onCameraModeChanged(GuidanceCameraMode mode) {
207 System.out.println("Guidance camera mode: " + mode);
208 }
209
210 @Override
211 public void onInstructionChanged(RouteInstruction instruction) {
212 System.out.println("Next: " + (instruction == null ? "none" : instruction.getTitle()));
213 }
214 });
215 // [java_GuidanceCamera_addListener]
216 }
217 // [java_NavigineSdk_getGuidanceCamera]
218
219 // [java_NavigineSdk_getRouteSimulator]
220 if (locationWindow != null) {
221 RouteSimulator routeSimulator = sdk.getRouteSimulator(locationWindow);
222 // [java_RouteSimulator_setGeometry]
223 List<GlobalPoint> walkPoints = new ArrayList<>();
224 walkPoints.add(new GlobalPoint(55.751, 37.618));
225 walkPoints.add(new GlobalPoint(55.752, 37.618));
226 routeSimulator.setGeometry(Collections.singletonList(new LocationPolyline(walkPoints, null)));
227 // [java_RouteSimulator_setGeometry]
228 // [java_RouteSimulator_setSpeed]
229 routeSimulator.setSpeed(1.4f);
230 // [java_RouteSimulator_setSpeed]
231 // [java_RouteSimulator_start]
232 boolean started = routeSimulator.start();
233 System.out.println("Route walk started: " + started);
234 // [java_RouteSimulator_start]
235 // [java_RouteSimulator_sample]
236 RouteSimulatorSample sample = routeSimulator.sample();
237 if (sample != null) {
238 System.out.println("Walk advance: " + sample.getAdvance() + " m");
239 }
240 // [java_RouteSimulator_sample]
241 }
242 // [java_NavigineSdk_getRouteSimulator]
243
244 // [java_NavigineSdk_getMqttSession]
245 // Get MqttSession for publishing position data via MQTT
246 if (navigationManager != null) {
247 mqttSession = sdk.getMqttSession(navigationManager);
248 if (mqttSession != null) {
249 System.out.println("MqttSession successfully initialized");
250 }
251 }
252 // [java_NavigineSdk_getMqttSession]
253 }
254
258 public void printSdkInfo() {
259 System.out.println("=== Navigine SDK Information ===");
260 System.out.println("SDK Version: " + NavigineSdk.getVersion());
261 System.out.println("Device ID: " + NavigineSdk.getDeviceId());
262 System.out.println("Relative Time: " + NavigineSdk.getRelativeTime());
263 System.out.println("LocationManager: " + (locationManager != null ? "available" : "unavailable"));
264 System.out.println("NavigationManager: " + (navigationManager != null ? "available" : "unavailable"));
265 System.out.println("ZoneManager: " + (zoneManager != null ? "available" : "unavailable"));
266 System.out.println("RouteManager: " + (routeManager != null ? "available" : "unavailable"));
267 System.out.println("AsyncRouteManager: " + (asyncRouteManager != null ? "available" : "unavailable"));
268 System.out.println("NotificationManager: " + (notificationManager != null ? "available" : "unavailable"));
269 System.out.println("MeasurementManager: " + (measurementManager != null ? "available" : "unavailable"));
270 System.out.println("LocationListManager: " + (locationListManager != null ? "available" : "unavailable"));
271 System.out.println("StorageManager: " + (storageManager != null ? "available" : "unavailable"));
272 System.out.println("MqttSession: " + (mqttSession != null ? "available" : "unavailable"));
273 }
274
279 System.out.println("=== Manager Usage Demonstration ===");
280
281 // LocationManager usage example
282 if (locationManager != null) {
283 System.out.println("LocationManager ready for location operations");
284 // Add code here for loading locations, working with them, etc.
285 }
286
287 // NavigationManager usage example
288 if (navigationManager != null) {
289 System.out.println("NavigationManager ready for positioning");
290 // Add code here for getting position, setting up listeners, etc.
291 }
292
293 // ZoneManager usage example
294 if (zoneManager != null) {
295 System.out.println("ZoneManager ready for zone operations");
296 // Add code here for setting up zones, handling enter/exit events, etc.
297 }
298
299 // RouteManager usage example
300 if (routeManager != null) {
301 System.out.println("RouteManager ready for route building");
302 // Add code here for building routes, setting destination points, etc.
303 }
304
305 // AsyncRouteManager usage example
306 if (asyncRouteManager != null) {
307 System.out.println("AsyncRouteManager ready for async route operations");
308 // Add code here for creating routing sessions, etc.
309 }
310
311 // NotificationManager usage example
312 if (notificationManager != null) {
313 System.out.println("NotificationManager ready for notifications");
314 // Add code here for setting up beacon notifications, etc.
315 }
316
317 // MeasurementManager usage example
318 if (measurementManager != null) {
319 System.out.println("MeasurementManager ready for measurements");
320 // Add code here for managing measurement generators, etc.
321 }
322
323 // LocationListManager usage example
324 if (locationListManager != null) {
325 System.out.println("LocationListManager ready for location list operations");
326 // Add code here for getting available locations list, etc.
327 }
328
329 // StorageManager usage example
330 if (storageManager != null) {
331 System.out.println("StorageManager ready for storage operations");
332 // Add code here for creating storages, managing data, etc.
333 }
334
335 // MqttSession usage example
336 if (mqttSession != null) {
337 System.out.println("MqttSession ready for publishing position data via MQTT");
338 // Add code here for connecting to MQTT broker, publishing positions, etc.
339 }
340 }
341
345 public static void main(String[] args) {
347 example.printSdkInfo();
348 example.demonstrateManagersUsage();
349 }
350}