Skip to content

Commit fd218b7

Browse files
Merge pull request #219 from heremaps/esd/41340
Update example apps for release 4.13.4.0
2 parents 0cefdc9 + ccdd453 commit fd218b7

File tree

13 files changed

+299
-45
lines changed

13 files changed

+299
-45
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.3.0)
29+
## List of Available Example Apps (Version 4.13.4.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.3.0
1+
This folder contains the HERE SDK examples apps for version: 4.13.4.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/MainActivity.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121

2222
import android.content.Context;
2323
import android.os.Bundle;
24+
import android.util.Log;
25+
import android.view.View;
26+
2427
import androidx.annotation.NonNull;
2528
import androidx.annotation.Nullable;
2629
import androidx.appcompat.app.AppCompatActivity;
27-
import android.util.Log;
28-
import android.view.View;
2930

3031
import com.here.sdk.core.engine.SDKNativeEngine;
3132
import com.here.sdk.core.engine.SDKOptions;
@@ -90,6 +91,7 @@ public void permissionsDenied() {
9091

9192
@Override
9293
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
94+
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
9395
permissionsRequestor.onRequestPermissionsResult(requestCode, grantResults);
9496
}
9597

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
import com.here.sdk.routing.RoutingError;
4747
import com.here.sdk.routing.Section;
4848
import com.here.sdk.routing.SectionNotice;
49+
import com.here.sdk.routing.Span;
50+
import com.here.sdk.routing.TrafficSpeed;
4951
import com.here.sdk.routing.Waypoint;
5052

5153
import java.text.DateFormat;
@@ -176,6 +178,9 @@ private void showRouteOnMap(Route route) {
176178
mapView.getMapScene().addMapPolyline(routeMapPolyline);
177179
mapPolylines.add(routeMapPolyline);
178180

181+
// Optionally, render traffic on route.
182+
showTrafficOnRoute(route);
183+
179184
GeoCoordinates startPoint =
180185
route.getSections().get(0).getDeparturePlace().mapMatchedCoordinates;
181186
GeoCoordinates destination =
@@ -258,6 +263,44 @@ private void clearRoute() {
258263
mapPolylines.clear();
259264
}
260265

266+
// This renders the traffic flow on top of the route as multiple MapPolylines per span.
267+
private void showTrafficOnRoute(Route route) {
268+
for (Section section : route.getSections()) {
269+
for (Span span : section.getSpans()) {
270+
GeoPolyline spanGeoPolyline;
271+
try {
272+
// A polyline needs to have two or more coordinates.
273+
spanGeoPolyline = new GeoPolyline(span.getPolyline());
274+
} catch (InstantiationErrorException e) {
275+
e.printStackTrace();
276+
return;
277+
}
278+
float widthInPixels = 10;
279+
TrafficSpeed trafficSpeed = span.getTrafficSpeed();
280+
Color lineColor = getTrafficColor(trafficSpeed.jamFactor);
281+
MapPolyline trafficSpanMapPolyline = new MapPolyline(spanGeoPolyline, widthInPixels, lineColor);
282+
mapView.getMapScene().addMapPolyline(trafficSpanMapPolyline);
283+
mapPolylines.add(trafficSpanMapPolyline);
284+
}
285+
}
286+
}
287+
288+
// Define a traffic color scheme based on the route's jam factor.
289+
// 0 <= jamFactor < 4: No or light traffic.
290+
// 4 <= jamFactor < 8: Moderate or slow traffic.
291+
// 8 <= jamFactor < 10: Severe traffic.
292+
// jamFactor = 10: No traffic, ie. the road is blocked.
293+
private Color getTrafficColor(Double jamFactor) {
294+
if (jamFactor == null || jamFactor < 4) {
295+
return Color.valueOf(0, 0, 0, 0); // Fully transparent (RGBA)
296+
} else if (jamFactor >= 4 && jamFactor < 8) {
297+
return Color.valueOf(1, 1, 0, 0.63f); // Yellow
298+
} else if (jamFactor >= 8 && jamFactor < 10) {
299+
return Color.valueOf(1, 0, 0, 0.63f); // Red
300+
}
301+
return Color.valueOf(0, 0, 0, 0.63f); // Black
302+
}
303+
261304
private GeoCoordinates createRandomGeoCoordinatesAroundMapCenter() {
262305
GeoCoordinates centerGeoCoordinates = mapView.viewToGeoCoordinates(
263306
new Point2D(mapView.getWidth() / 2, mapView.getHeight() / 2));

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

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
*/
1919

2020
import 'dart:math';
21-
import 'package:intl/intl.dart';
21+
2222
import 'package:flutter/material.dart';
23+
import 'package:here_sdk/animation.dart';
2324
import 'package:here_sdk/core.dart';
2425
import 'package:here_sdk/core.errors.dart';
2526
import 'package:here_sdk/mapview.dart';
26-
import 'package:here_sdk/animation.dart';
2727
import 'package:here_sdk/routing.dart';
2828
import 'package:here_sdk/routing.dart' as here;
29+
import 'package:intl/intl.dart';
2930

3031
// A callback to notify the hosting widget.
3132
typedef ShowDialogFunction = void Function(String title, String message);
@@ -99,7 +100,7 @@ class RoutingExample {
99100
for (int i = 0; i < route.sections.length; i++) {
100101
Section section = route.sections.elementAt(i);
101102

102-
print("Route Section : " + (i+1).toString());
103+
print("Route Section : " + (i + 1).toString());
103104
print("Route Section Departure Time : " + dateFormat.format(section.departureLocationTime!.localTime));
104105
print("Route Section Arrival Time : " + dateFormat.format(section.arrivalLocationTime!.localTime));
105106
print("Route Section length : " + section.lengthInMeters.toString() + " m");
@@ -112,9 +113,12 @@ class RoutingExample {
112113
int estimatedTrafficDelayInSeconds = route.trafficDelay.inSeconds;
113114
int lengthInMeters = route.lengthInMeters;
114115

115-
String routeDetails = 'Travel Time: ' + _formatTime(estimatedTravelTimeInSeconds)
116-
+ ', Traffic Delay: ' + _formatTime(estimatedTrafficDelayInSeconds)
117-
+ ', Length: ' + _formatLength(lengthInMeters);
116+
String routeDetails = 'Travel Time: ' +
117+
_formatTime(estimatedTravelTimeInSeconds) +
118+
', Traffic Delay: ' +
119+
_formatTime(estimatedTrafficDelayInSeconds) +
120+
', Length: ' +
121+
_formatLength(lengthInMeters);
118122

119123
_showDialog('Route Details', '$routeDetails');
120124
}
@@ -140,6 +144,47 @@ class RoutingExample {
140144
MapPolyline routeMapPolyline = MapPolyline(routeGeoPolyline, widthInPixels, Color.fromARGB(160, 0, 144, 138));
141145
_hereMapController.mapScene.addMapPolyline(routeMapPolyline);
142146
_mapPolylines.add(routeMapPolyline);
147+
148+
// Optionally, render traffic on route.
149+
_showTrafficOnRoute(route);
150+
}
151+
152+
// This renders the traffic flow on top of the route as multiple MapPolylines per span.
153+
_showTrafficOnRoute(here.Route route) {
154+
for (var section in route.sections) {
155+
for (var span in section.spans) {
156+
GeoPolyline spanGeoPolyline;
157+
try {
158+
// A polyline needs to have two or more coordinates.
159+
spanGeoPolyline = GeoPolyline(span.polyline);
160+
} on InstantiationException {
161+
print("Error: Initialization of GeoPolyline failed.");
162+
return;
163+
}
164+
double widthInPixels = 10;
165+
TrafficSpeed trafficSpeed = span.trafficSpeed;
166+
Color lineColor = _getTrafficColor(trafficSpeed.jamFactor ?? 0);
167+
MapPolyline trafficSpanMapPolyline = new MapPolyline(spanGeoPolyline, widthInPixels, lineColor);
168+
_hereMapController.mapScene.addMapPolyline(trafficSpanMapPolyline);
169+
_mapPolylines.add(trafficSpanMapPolyline);
170+
}
171+
}
172+
}
173+
174+
// Define a traffic color scheme based on the route's jam factor.
175+
// 0 <= jamFactor < 4: No or light traffic.
176+
// 4 <= jamFactor < 8: Moderate or slow traffic.
177+
// 8 <= jamFactor < 10: Severe traffic.
178+
// 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
182+
} else if (jamFactor >= 4 && jamFactor < 8) {
183+
return Color.fromARGB(160, 255, 255, 0); // Yellow
184+
} else if (jamFactor >= 8 && jamFactor < 10) {
185+
return Color.fromARGB(160, 255, 0, 0); // Red
186+
}
187+
return Color.fromARGB(160, 0, 0, 0); // Black
143188
}
144189

145190
GeoCoordinates _createRandomGeoCoordinatesInViewport() {
@@ -174,13 +219,13 @@ class RoutingExample {
174219
double tilt = 0;
175220
// We want to show the route fitting in the map view with an additional padding of 50 pixels.
176221
Point2D origin = Point2D(50, 50);
177-
Size2D sizeInPixels = Size2D(_hereMapController.viewportSize.width - 100, _hereMapController.viewportSize.height - 100);
222+
Size2D sizeInPixels =
223+
Size2D(_hereMapController.viewportSize.width - 100, _hereMapController.viewportSize.height - 100);
178224
Rectangle2D mapViewport = Rectangle2D(origin, sizeInPixels);
179225

180226
// Animate to the route within a duration of 3 seconds.
181-
MapCameraUpdate update = MapCameraUpdateFactory.lookAtAreaWithGeoOrientationAndViewRectangle(route!.boundingBox,
182-
GeoOrientationUpdate(bearing, tilt),
183-
mapViewport);
227+
MapCameraUpdate update = MapCameraUpdateFactory.lookAtAreaWithGeoOrientationAndViewRectangle(
228+
route!.boundingBox, GeoOrientationUpdate(bearing, tilt), mapViewport);
184229
MapCameraAnimation animation = MapCameraAnimationFactory.createAnimationFromUpdate(
185230
update, const Duration(milliseconds: 3000), EasingFunction.inCubic);
186231
_hereMapController.camera.startAnimation(animation);

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ class RoutingExample {
133133
mapView.mapScene.addMapPolyline(routeMapPolyline)
134134
mapPolylineList.append(routeMapPolyline)
135135

136+
// Optionally, render traffic on route.
137+
showTrafficOnRoute(route)
138+
136139
let startPoint = route.sections.first!.departurePlace.mapMatchedCoordinates
137140
let destination = route.sections.last!.arrivalPlace.mapMatchedCoordinates
138141

@@ -196,6 +199,41 @@ class RoutingExample {
196199
}
197200
}
198201

202+
// This renders the traffic flow on top of the route as multiple MapPolylines per span.
203+
private func showTrafficOnRoute(_ route: Route) {
204+
for section in route.sections {
205+
for span in section.spans {
206+
// A polyline needs to have two or more coordinates.
207+
guard let spanGeoPolyline = try? GeoPolyline(vertices: span.polyline) else {
208+
print("Error: Initialization of GeoPolyline failed.")
209+
return
210+
}
211+
let trafficSpeed = span.trafficSpeed
212+
let trafficSpanMapPolyline = MapPolyline(geometry: spanGeoPolyline,
213+
widthInPixels: 10,
214+
color: getTrafficColor(trafficSpeed.jamFactor ?? 0))
215+
mapView.mapScene.addMapPolyline(trafficSpanMapPolyline)
216+
mapPolylineList.append(trafficSpanMapPolyline)
217+
}
218+
}
219+
}
220+
221+
// Define a traffic color scheme based on the route's jam factor.
222+
// 0 <= jamFactor < 4: No or light traffic.
223+
// 4 <= jamFactor < 8: Moderate or slow traffic.
224+
// 8 <= jamFactor < 10: Severe traffic.
225+
// 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+
}
236+
199237
func clearMap() {
200238
clearWaypointMapMarker()
201239
clearRoute()

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121

2222
import android.content.Context;
2323
import android.os.Bundle;
24+
import android.util.Log;
25+
import android.view.View;
26+
2427
import androidx.annotation.NonNull;
2528
import androidx.annotation.Nullable;
2629
import androidx.appcompat.app.AppCompatActivity;
27-
import android.util.Log;
28-
import android.view.View;
2930

3031
import com.here.sdk.core.engine.SDKNativeEngine;
3132
import com.here.sdk.core.engine.SDKOptions;
@@ -90,6 +91,7 @@ public void permissionsDenied() {
9091

9192
@Override
9293
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
94+
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
9395
permissionsRequestor.onRequestPermissionsResult(requestCode, grantResults);
9496
}
9597

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
import com.here.sdk.routing.RoutingError;
4747
import com.here.sdk.routing.Section;
4848
import com.here.sdk.routing.SectionNotice;
49+
import com.here.sdk.routing.Span;
50+
import com.here.sdk.routing.TrafficSpeed;
4951
import com.here.sdk.routing.Waypoint;
5052

5153
import java.text.DateFormat;
@@ -176,6 +178,9 @@ private void showRouteOnMap(Route route) {
176178
mapView.getMapScene().addMapPolyline(routeMapPolyline);
177179
mapPolylines.add(routeMapPolyline);
178180

181+
// Optionally, render traffic on route.
182+
showTrafficOnRoute(route);
183+
179184
GeoCoordinates startPoint =
180185
route.getSections().get(0).getDeparturePlace().mapMatchedCoordinates;
181186
GeoCoordinates destination =
@@ -258,6 +263,44 @@ private void clearRoute() {
258263
mapPolylines.clear();
259264
}
260265

266+
// This renders the traffic flow on top of the route as multiple MapPolylines per span.
267+
private void showTrafficOnRoute(Route route) {
268+
for (Section section : route.getSections()) {
269+
for (Span span : section.getSpans()) {
270+
GeoPolyline spanGeoPolyline;
271+
try {
272+
// A polyline needs to have two or more coordinates.
273+
spanGeoPolyline = new GeoPolyline(span.getPolyline());
274+
} catch (InstantiationErrorException e) {
275+
e.printStackTrace();
276+
return;
277+
}
278+
float widthInPixels = 10;
279+
TrafficSpeed trafficSpeed = span.getTrafficSpeed();
280+
Color lineColor = getTrafficColor(trafficSpeed.jamFactor);
281+
MapPolyline trafficSpanMapPolyline = new MapPolyline(spanGeoPolyline, widthInPixels, lineColor);
282+
mapView.getMapScene().addMapPolyline(trafficSpanMapPolyline);
283+
mapPolylines.add(trafficSpanMapPolyline);
284+
}
285+
}
286+
}
287+
288+
// Define a traffic color scheme based on the route's jam factor.
289+
// 0 <= jamFactor < 4: No or light traffic.
290+
// 4 <= jamFactor < 8: Moderate or slow traffic.
291+
// 8 <= jamFactor < 10: Severe traffic.
292+
// jamFactor = 10: No traffic, ie. the road is blocked.
293+
private Color getTrafficColor(Double jamFactor) {
294+
if (jamFactor == null || jamFactor < 4) {
295+
return Color.valueOf(0, 0, 0, 0); // Fully transparent (RGBA)
296+
} else if (jamFactor >= 4 && jamFactor < 8) {
297+
return Color.valueOf(1, 1, 0, 0.63f); // Yellow
298+
} else if (jamFactor >= 8 && jamFactor < 10) {
299+
return Color.valueOf(1, 0, 0, 0.63f); // Red
300+
}
301+
return Color.valueOf(0, 0, 0, 0.63f); // Black
302+
}
303+
261304
private GeoCoordinates createRandomGeoCoordinatesAroundMapCenter() {
262305
GeoCoordinates centerGeoCoordinates = mapView.viewToGeoCoordinates(
263306
new Point2D(mapView.getWidth() / 2, mapView.getHeight() / 2));

0 commit comments

Comments
 (0)