Skip to content

Commit d1baba6

Browse files
Merge pull request #227 from heremaps/esd/41350
Update example apps for release 4.13.5.0
2 parents eaf4188 + 35b220c commit d1baba6

File tree

13 files changed

+204
-118
lines changed

13 files changed

+204
-118
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ For an overview of the existing features, please check the _Developer's Guide_ f
2626

2727
> For now, the _Navigate Edition_ is only available upon request. Please contact your HERE representative to receive access including a set of evaluation credentials.
2828
29-
## List of Available Example Apps (Version 4.13.4.0)
29+
## List of Available Example Apps (Version 4.13.5.0)
3030

3131
- **HelloMap**: Shows the classic 'Hello World'.
3232
- **HelloMapKotlin**: Shows the classic 'Hello World' using Kotlin language (Android only).

examples/latest/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
This folder contains the HERE SDK examples apps for version: 4.13.4.0
1+
This folder contains the HERE SDK examples apps for version: 4.13.5.0
22

33
- HERE SDK for Android ([Lite Edition](lite/android/), [Explore Edition](explore/android/), [Navigate Edition](navigate/android/))
44
- HERE SDK for iOS ([Lite Edition](lite/ios/), [Explore Edition](explore/ios/), [Navigate Edition](navigate/ios/))

examples/latest/explore/android/Routing/app/src/main/java/com/here/routing/RoutingExample.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.here.sdk.core.GeoPolyline;
3131
import com.here.sdk.core.Point2D;
3232
import com.here.sdk.core.errors.InstantiationErrorException;
33+
import com.here.sdk.core.threading.TaskHandle;
3334
import com.here.sdk.mapview.MapCamera;
3435
import com.here.sdk.mapview.MapImage;
3536
import com.here.sdk.mapview.MapImageFactory;
@@ -125,15 +126,15 @@ private void logRouteViolations(Route route) {
125126
private void logRouteSectionDetails(Route route) {
126127
DateFormat dateFormat = new SimpleDateFormat("HH:mm");
127128

128-
for (int i = 0; i< route.getSections().size(); i++) {
129+
for (int i = 0; i < route.getSections().size(); i++) {
129130
Section section = route.getSections().get(i);
130131

131-
Log.d(TAG, "Route Section : " + (i+1));
132+
Log.d(TAG, "Route Section : " + (i + 1));
132133
Log.d(TAG, "Route Section Departure Time : "
133134
+ dateFormat.format(section.getDepartureLocationTime().localTime));
134135
Log.d(TAG, "Route Section Arrival Time : "
135136
+ dateFormat.format(section.getArrivalLocationTime().localTime));
136-
Log.d(TAG, "Route Section length : " + section.getLengthInMeters() + " m");
137+
Log.d(TAG, "Route Section length : " + section.getLengthInMeters() + " m");
137138
Log.d(TAG, "Route Section duration : " + section.getDuration().getSeconds() + " s");
138139
}
139140
}
@@ -144,8 +145,8 @@ private void showRouteDetails(Route route) {
144145
int lengthInMeters = route.getLengthInMeters();
145146

146147
String routeDetails = "Travel Time: " + formatTime(estimatedTravelTimeInSeconds)
147-
+ ", traffic delay: " + formatTime(estimatedTrafficDelayInSeconds)
148-
+ ", Length: " + formatLength(lengthInMeters);
148+
+ ", traffic delay: " + formatTime(estimatedTrafficDelayInSeconds)
149+
+ ", Length: " + formatLength(lengthInMeters);
149150

150151
showDialog("Route Details", routeDetails);
151152
}
@@ -265,8 +266,19 @@ private void clearRoute() {
265266

266267
// This renders the traffic flow on top of the route as multiple MapPolylines per span.
267268
private void showTrafficOnRoute(Route route) {
269+
if (route.getLengthInMeters() / 1000 > 5000) {
270+
Log.d(TAG, "Skip showing traffic-on-route for longer routes.");
271+
return;
272+
}
273+
268274
for (Section section : route.getSections()) {
269275
for (Span span : section.getSpans()) {
276+
TrafficSpeed trafficSpeed = span.getTrafficSpeed();
277+
Color lineColor = getTrafficColor(trafficSpeed.jamFactor);
278+
if (lineColor == null) {
279+
// We skip rendering low traffic.
280+
continue;
281+
}
270282
GeoPolyline spanGeoPolyline;
271283
try {
272284
// A polyline needs to have two or more coordinates.
@@ -276,8 +288,6 @@ private void showTrafficOnRoute(Route route) {
276288
return;
277289
}
278290
float widthInPixels = 10;
279-
TrafficSpeed trafficSpeed = span.getTrafficSpeed();
280-
Color lineColor = getTrafficColor(trafficSpeed.jamFactor);
281291
MapPolyline trafficSpanMapPolyline = new MapPolyline(spanGeoPolyline, widthInPixels, lineColor);
282292
mapView.getMapScene().addMapPolyline(trafficSpanMapPolyline);
283293
mapPolylines.add(trafficSpanMapPolyline);
@@ -290,9 +300,11 @@ private void showTrafficOnRoute(Route route) {
290300
// 4 <= jamFactor < 8: Moderate or slow traffic.
291301
// 8 <= jamFactor < 10: Severe traffic.
292302
// jamFactor = 10: No traffic, ie. the road is blocked.
303+
// Returns null in case of no or light traffic.
304+
@Nullable
293305
private Color getTrafficColor(Double jamFactor) {
294306
if (jamFactor == null || jamFactor < 4) {
295-
return Color.valueOf(0, 0, 0, 0); // Fully transparent (RGBA)
307+
return null;
296308
} else if (jamFactor >= 4 && jamFactor < 8) {
297309
return Color.valueOf(1, 1, 0, 0.63f); // Yellow
298310
} else if (jamFactor >= 8 && jamFactor < 10) {

examples/latest/explore/flutter/routing_app/lib/RoutingExample.dart

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,19 @@ class RoutingExample {
151151

152152
// This renders the traffic flow on top of the route as multiple MapPolylines per span.
153153
_showTrafficOnRoute(here.Route route) {
154+
if (route.lengthInMeters / 1000 > 5000) {
155+
print("Skip showing traffic-on-route for longer routes.");
156+
return;
157+
}
158+
154159
for (var section in route.sections) {
155160
for (var span in section.spans) {
161+
TrafficSpeed trafficSpeed = span.trafficSpeed;
162+
Color? lineColor = _getTrafficColor(trafficSpeed.jamFactor);
163+
if (lineColor == null) {
164+
// We skip rendering low traffic.
165+
continue;
166+
}
156167
GeoPolyline spanGeoPolyline;
157168
try {
158169
// A polyline needs to have two or more coordinates.
@@ -162,8 +173,6 @@ class RoutingExample {
162173
return;
163174
}
164175
double widthInPixels = 10;
165-
TrafficSpeed trafficSpeed = span.trafficSpeed;
166-
Color lineColor = _getTrafficColor(trafficSpeed.jamFactor ?? 0);
167176
MapPolyline trafficSpanMapPolyline = new MapPolyline(spanGeoPolyline, widthInPixels, lineColor);
168177
_hereMapController.mapScene.addMapPolyline(trafficSpanMapPolyline);
169178
_mapPolylines.add(trafficSpanMapPolyline);
@@ -176,9 +185,10 @@ class RoutingExample {
176185
// 4 <= jamFactor < 8: Moderate or slow traffic.
177186
// 8 <= jamFactor < 10: Severe traffic.
178187
// jamFactor = 10: No traffic, ie. the road is blocked.
179-
Color _getTrafficColor(double jamFactor) {
180-
if (jamFactor < 4) {
181-
return Color.fromARGB(0, 0, 0, 0); // Fully transparent
188+
// Returns null in case of no or light traffic.
189+
Color? _getTrafficColor(double? jamFactor) {
190+
if (jamFactor == null || jamFactor < 4) {
191+
return null;
182192
} else if (jamFactor >= 4 && jamFactor < 8) {
183193
return Color.fromARGB(160, 255, 255, 0); // Yellow
184194
} else if (jamFactor >= 8 && jamFactor < 10) {

examples/latest/explore/ios/Routing/Routing/RoutingExample.swift

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ class RoutingExample {
7878
}
7979
}
8080
}
81-
81+
8282
private func logRouteSectionDetails(route: Route) {
8383
let dateFormatter = DateFormatter()
8484
dateFormatter.dateFormat = "HH:mm"
85-
85+
8686
for (i, sections) in route.sections.enumerated() {
8787
print("Route Section : " + String(i));
8888
print("Route Section Departure Time : " + dateFormatter.string(from: sections.departureLocationTime!.localTime));
@@ -96,7 +96,7 @@ class RoutingExample {
9696
let estimatedTravelTimeInSeconds = route.duration
9797
let estimatedTrafficDelayInSeconds = route.trafficDelay
9898
let lengthInMeters = route.lengthInMeters
99-
99+
100100
let routeDetails = "Travel Time (h:m): " + formatTime(sec: estimatedTravelTimeInSeconds)
101101
+ ", Traffic Delay (h:m): " + formatTime(sec: estimatedTrafficDelayInSeconds)
102102
+ ", Length: " + formatLength(meters: lengthInMeters)
@@ -121,7 +121,7 @@ class RoutingExample {
121121
private func showRouteOnMap(route: Route) {
122122
// Optionally, clear any previous route.
123123
clearMap()
124-
124+
125125
// Show route as polyline.
126126
let routeGeoPolyline = route.geometry
127127
let routeMapPolyline = MapPolyline(geometry: routeGeoPolyline,
@@ -135,10 +135,10 @@ class RoutingExample {
135135

136136
// Optionally, render traffic on route.
137137
showTrafficOnRoute(route)
138-
138+
139139
let startPoint = route.sections.first!.departurePlace.mapMatchedCoordinates
140140
let destination = route.sections.last!.arrivalPlace.mapMatchedCoordinates
141-
141+
142142
// Draw a circle to indicate starting point and destination.
143143
addCircleMapMarker(geoCoordinates: startPoint, imageName: "green_dot.png")
144144
addCircleMapMarker(geoCoordinates: destination, imageName: "green_dot.png")
@@ -201,17 +201,26 @@ class RoutingExample {
201201

202202
// This renders the traffic flow on top of the route as multiple MapPolylines per span.
203203
private func showTrafficOnRoute(_ route: Route) {
204+
if route.lengthInMeters / 1000 > 5000 {
205+
print("Skip showing traffic-on-route for longer routes.");
206+
return
207+
}
208+
204209
for section in route.sections {
205210
for span in section.spans {
211+
let trafficSpeed = span.trafficSpeed
212+
guard let lineColor = getTrafficColor(trafficSpeed.jamFactor) else {
213+
// Skip rendering low traffic.
214+
continue
215+
}
206216
// A polyline needs to have two or more coordinates.
207217
guard let spanGeoPolyline = try? GeoPolyline(vertices: span.polyline) else {
208218
print("Error: Initialization of GeoPolyline failed.")
209219
return
210220
}
211-
let trafficSpeed = span.trafficSpeed
212221
let trafficSpanMapPolyline = MapPolyline(geometry: spanGeoPolyline,
213222
widthInPixels: 10,
214-
color: getTrafficColor(trafficSpeed.jamFactor ?? 0))
223+
color: lineColor)
215224
mapView.mapScene.addMapPolyline(trafficSpanMapPolyline)
216225
mapPolylineList.append(trafficSpanMapPolyline)
217226
}
@@ -223,17 +232,21 @@ class RoutingExample {
223232
// 4 <= jamFactor < 8: Moderate or slow traffic.
224233
// 8 <= jamFactor < 10: Severe traffic.
225234
// jamFactor = 10: No traffic, ie. the road is blocked.
226-
private func getTrafficColor(_ jamFactor: Double) -> UIColor {
227-
if (jamFactor < 4) {
228-
return UIColor(red: 0, green: 0, blue: 0, alpha: 0) // Fully transparent
229-
} else if (jamFactor >= 4 && jamFactor < 8) {
230-
return UIColor(red: 1, green: 1, blue: 0, alpha: 0.63) // Yellow
231-
} else if (jamFactor >= 8 && jamFactor < 10) {
232-
return UIColor(red: 1, green: 0, blue: 0, alpha: 0.63) // Red
233-
}
234-
return UIColor(red: 0, green: 0, blue: 0, alpha: 0.63) // Black
235+
// Returns nil in case of no or light traffic.
236+
private func getTrafficColor(_ jamFactor: Double?) -> UIColor? {
237+
guard let jamFactor = jamFactor else {
238+
return nil
239+
}
240+
if jamFactor < 4 {
241+
return nil
242+
} else if jamFactor >= 4 && jamFactor < 8 {
243+
return UIColor(red: 1, green: 1, blue: 0, alpha: 0.63) // Yellow
244+
} else if jamFactor >= 8 && jamFactor < 10 {
245+
return UIColor(red: 1, green: 0, blue: 0, alpha: 0.63) // Red
246+
}
247+
return UIColor(red: 0, green: 0, blue: 0, alpha: 0.63) // Black
235248
}
236-
249+
237250
func clearMap() {
238251
clearWaypointMapMarker()
239252
clearRoute()

examples/latest/navigate/android/Navigation/app/src/main/java/com/here/navigation/NavigationExample.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,11 @@ public void onRealisticViewWarningUpdated(@NonNull RealisticViewWarning realisti
563563
}
564564

565565
RealisticView realisticView = realisticViewWarning.realisticView;
566+
if (realisticView == null) {
567+
Log.d(TAG, "A RealisticView just passed. No SVG data delivered.");
568+
return;
569+
}
570+
566571
String signpostSvgImageContent = realisticView.signpostSvgImageContent;
567572
String junctionViewSvgImageContent = realisticView.junctionViewSvgImageContent;
568573
// The resolution-independent SVG data can now be used in an application to visualize the image.
@@ -582,9 +587,9 @@ private String getRoadName(Maneuver maneuver) {
582587
RoadTexts nextRoadTexts = maneuver.getNextRoadTexts();
583588

584589
String currentRoadName = currentRoadTexts.names.getDefaultValue();
585-
String currentRoadNumber = currentRoadTexts.numbers.getDefaultValue();
590+
String currentRoadNumber = currentRoadTexts.numbersWithDirection.getDefaultValue();
586591
String nextRoadName = nextRoadTexts.names.getDefaultValue();
587-
String nextRoadNumber = nextRoadTexts.numbers.getDefaultValue();
592+
String nextRoadNumber = nextRoadTexts.numbersWithDirection.getDefaultValue();
588593

589594
String roadName = nextRoadName == null ? nextRoadNumber : nextRoadName;
590595

examples/latest/navigate/android/Routing/app/src/main/java/com/here/routing/RoutingExample.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.here.sdk.core.GeoPolyline;
3131
import com.here.sdk.core.Point2D;
3232
import com.here.sdk.core.errors.InstantiationErrorException;
33+
import com.here.sdk.core.threading.TaskHandle;
3334
import com.here.sdk.mapview.MapCamera;
3435
import com.here.sdk.mapview.MapImage;
3536
import com.here.sdk.mapview.MapImageFactory;
@@ -125,15 +126,15 @@ private void logRouteViolations(Route route) {
125126
private void logRouteSectionDetails(Route route) {
126127
DateFormat dateFormat = new SimpleDateFormat("HH:mm");
127128

128-
for (int i = 0; i< route.getSections().size(); i++) {
129+
for (int i = 0; i < route.getSections().size(); i++) {
129130
Section section = route.getSections().get(i);
130131

131-
Log.d(TAG, "Route Section : " + (i+1));
132+
Log.d(TAG, "Route Section : " + (i + 1));
132133
Log.d(TAG, "Route Section Departure Time : "
133134
+ dateFormat.format(section.getDepartureLocationTime().localTime));
134135
Log.d(TAG, "Route Section Arrival Time : "
135136
+ dateFormat.format(section.getArrivalLocationTime().localTime));
136-
Log.d(TAG, "Route Section length : " + section.getLengthInMeters() + " m");
137+
Log.d(TAG, "Route Section length : " + section.getLengthInMeters() + " m");
137138
Log.d(TAG, "Route Section duration : " + section.getDuration().getSeconds() + " s");
138139
}
139140
}
@@ -144,8 +145,8 @@ private void showRouteDetails(Route route) {
144145
int lengthInMeters = route.getLengthInMeters();
145146

146147
String routeDetails = "Travel Time: " + formatTime(estimatedTravelTimeInSeconds)
147-
+ ", traffic delay: " + formatTime(estimatedTrafficDelayInSeconds)
148-
+ ", Length: " + formatLength(lengthInMeters);
148+
+ ", traffic delay: " + formatTime(estimatedTrafficDelayInSeconds)
149+
+ ", Length: " + formatLength(lengthInMeters);
149150

150151
showDialog("Route Details", routeDetails);
151152
}
@@ -265,8 +266,19 @@ private void clearRoute() {
265266

266267
// This renders the traffic flow on top of the route as multiple MapPolylines per span.
267268
private void showTrafficOnRoute(Route route) {
269+
if (route.getLengthInMeters() / 1000 > 5000) {
270+
Log.d(TAG, "Skip showing traffic-on-route for longer routes.");
271+
return;
272+
}
273+
268274
for (Section section : route.getSections()) {
269275
for (Span span : section.getSpans()) {
276+
TrafficSpeed trafficSpeed = span.getTrafficSpeed();
277+
Color lineColor = getTrafficColor(trafficSpeed.jamFactor);
278+
if (lineColor == null) {
279+
// We skip rendering low traffic.
280+
continue;
281+
}
270282
GeoPolyline spanGeoPolyline;
271283
try {
272284
// A polyline needs to have two or more coordinates.
@@ -276,8 +288,6 @@ private void showTrafficOnRoute(Route route) {
276288
return;
277289
}
278290
float widthInPixels = 10;
279-
TrafficSpeed trafficSpeed = span.getTrafficSpeed();
280-
Color lineColor = getTrafficColor(trafficSpeed.jamFactor);
281291
MapPolyline trafficSpanMapPolyline = new MapPolyline(spanGeoPolyline, widthInPixels, lineColor);
282292
mapView.getMapScene().addMapPolyline(trafficSpanMapPolyline);
283293
mapPolylines.add(trafficSpanMapPolyline);
@@ -290,9 +300,11 @@ private void showTrafficOnRoute(Route route) {
290300
// 4 <= jamFactor < 8: Moderate or slow traffic.
291301
// 8 <= jamFactor < 10: Severe traffic.
292302
// jamFactor = 10: No traffic, ie. the road is blocked.
303+
// Returns null in case of no or light traffic.
304+
@Nullable
293305
private Color getTrafficColor(Double jamFactor) {
294306
if (jamFactor == null || jamFactor < 4) {
295-
return Color.valueOf(0, 0, 0, 0); // Fully transparent (RGBA)
307+
return null;
296308
} else if (jamFactor >= 4 && jamFactor < 8) {
297309
return Color.valueOf(1, 1, 0, 0.63f); // Yellow
298310
} else if (jamFactor >= 8 && jamFactor < 10) {

examples/latest/navigate/flutter/navigation_app/lib/NavigationExample.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ class NavigationExample {
210210
RoadTexts nextRoadTexts = maneuver.nextRoadTexts;
211211

212212
String? currentRoadName = currentRoadTexts.names.getDefaultValue();
213-
String? currentRoadNumber = currentRoadTexts.numbers.getDefaultValue();
213+
String? currentRoadNumber = currentRoadTexts.numbersWithDirection.getDefaultValue();
214214
String? nextRoadName = nextRoadTexts.names.getDefaultValue();
215-
String? nextRoadNumber = nextRoadTexts.numbers.getDefaultValue();
215+
String? nextRoadNumber = nextRoadTexts.numbersWithDirection.getDefaultValue();
216216

217217
String? roadName = nextRoadName == null ? nextRoadNumber : nextRoadName;
218218

@@ -584,7 +584,12 @@ class NavigationExample {
584584
print("A RealisticView just passed.");
585585
}
586586

587-
RealisticView realisticView = realisticViewWarning.realisticView;
587+
RealisticView? realisticView = realisticViewWarning.realisticView;
588+
if (realisticView == null) {
589+
print("A RealisticView just passed. No SVG content delivered.");
590+
return;
591+
}
592+
588593
String signpostSvgImageContent = realisticView.signpostSvgImageContent;
589594
String junctionViewSvgImageContent = realisticView.junctionViewSvgImageContent;
590595
// The resolution-independent SVG data can now be used in an application to visualize the image.

0 commit comments

Comments
 (0)