use of com.zendrive.sdk.LocationPointWithTimestamp in project zendrive-sdk-android-sample by zendrive.
the class MockDriveLayoutHandler method simulateCustomMockDrive.
/**
* To create a completely new MockDrive from scratch use the MockDrive.Builder API.
*/
private MockZendriveOperationResult simulateCustomMockDrive(Context context) {
long driveStartTimestamp = 1543870794382L;
long driveEndTimestamp = 1543871176352L;
ArrayList<LocationPointWithTimestamp> waypoints = new ArrayList<>();
LocationPoint startLocationPoint = new LocationPoint(27.4293013, -82.5636051);
LocationPoint endLocationPoint = new LocationPoint(27.4265938, -82.5306409);
LocationPoint hardTurnStartLocation = new LocationPoint(27.429106, -82.530999);
LocationPoint hardTurnEndLocation = new LocationPoint(27.428820, -82.530591);
LocationPoint collisionLocation = new LocationPoint(27.427161, -82.530617);
LocationPoint aggressiveAccelerationLocation = new LocationPoint(27.429283, -82.546828);
LocationPoint hardBrakeLocation = new LocationPoint(27.429312, -82.548994);
LocationPoint phoneHandlingStartLocation = new LocationPoint(27.427824, -82.530598);
LocationPoint phoneHandlingEndLocation = new LocationPoint(27.426933, -82.530628);
LocationPoint speedingStartLocationPoint = new LocationPoint(27.429316, -82.559140);
LocationPoint speedingEndLocationPoint = new LocationPoint(27.429290, -82.557029);
LocationPoint phoneScreenInteractionStartLocation = new LocationPoint(27.429330, -82.562356);
LocationPoint phoneScreenInteractionEndLocation = new LocationPoint(27.429259, -82.560129);
LocationPoint stopSignViolationLocationPoint = new LocationPoint(27.429191, -82.540527);
waypoints.add(new LocationPointWithTimestamp(startLocationPoint, driveStartTimestamp));
waypoints.add(new LocationPointWithTimestamp(phoneScreenInteractionStartLocation, 1543870802367L));
waypoints.add(new LocationPointWithTimestamp(phoneScreenInteractionEndLocation, 1543870815396L));
waypoints.add(new LocationPointWithTimestamp(speedingStartLocationPoint, 1543870828368L));
waypoints.add(new LocationPointWithTimestamp(speedingEndLocationPoint, 1543870846391L));
waypoints.add(new LocationPointWithTimestamp(hardBrakeLocation, 1543871082354L));
waypoints.add(new LocationPointWithTimestamp(aggressiveAccelerationLocation, 1543871124370L));
waypoints.add(new LocationPointWithTimestamp(stopSignViolationLocationPoint, 1543871128383L));
waypoints.add(new LocationPointWithTimestamp(hardTurnStartLocation, 1543871132397L));
waypoints.add(new LocationPointWithTimestamp(hardTurnEndLocation, 1543871142367L));
waypoints.add(new LocationPointWithTimestamp(phoneHandlingStartLocation, 1543871149359L));
waypoints.add(new LocationPointWithTimestamp(phoneHandlingEndLocation, 1543871159381L));
waypoints.add(new LocationPointWithTimestamp(collisionLocation, 1543871167418L));
waypoints.add(new LocationPointWithTimestamp(endLocationPoint, driveEndTimestamp));
MockEventBuilder aggressiveAccelerationEventBuilder = new AggressiveAccelerationEventBuilder(1543871082354L).setLocation(aggressiveAccelerationLocation).setSeverity(ZendriveEventSeverity.HIGH);
MockEventBuilder collisionEventBuilder = new CollisionEventBuilder(1543871082354L, driveStartTimestamp, "accidentId", ZendriveAccidentConfidence.HIGH, 70, ZendriveVehicleType.CAR, ZendriveCollisionSeverity.HIGH).setLocation(collisionLocation);
MockEventBuilder hardBrakeEventBuilder = new HardBrakeEventBuilder(1543871082354L).setLocation(hardBrakeLocation).setSeverity(ZendriveEventSeverity.LOW);
MockEventBuilder speedingEventBuilder = new SpeedingEventBuilder(1543871124370L, 1543871132397L).setSpeedingInfo(35, 40, 25).setLocation(speedingStartLocationPoint, speedingEndLocationPoint).setSeverity(ZendriveEventSeverity.NOT_AVAILABLE);
MockEventBuilder phoneScreenInteractionEventBuilder = new PhoneScreenInteractionEventBuilder(1543871124370L, 1543871132397L).setLocation(phoneScreenInteractionStartLocation, phoneScreenInteractionEndLocation).setSeverity(ZendriveEventSeverity.NOT_AVAILABLE);
MockEventBuilder phoneHandlingEventBuilder = new PhoneHandlingEventBuilder(1543871124370L, 1543871132397L).setLocation(phoneHandlingStartLocation, phoneHandlingEndLocation).setSeverity(ZendriveEventSeverity.NOT_AVAILABLE);
MockEventBuilder hardTurnEventBuilder = new HardTurnEventBuilder(1543871124370L, 1543871132397L, ZendriveTurnDirection.RIGHT).setLocation(hardTurnStartLocation, hardTurnEndLocation).setSeverity(ZendriveEventSeverity.NOT_AVAILABLE);
MockEventBuilder stopSignViolationEventBuilder = new StopSignViolationEventBuilder(1543871128383L).setLocation(stopSignViolationLocationPoint).setSeverity(ZendriveEventSeverity.NOT_AVAILABLE);
ZendriveEventRatings eventRatings = new ZendriveEventRatings();
eventRatings.aggressiveAccelerationRating = ZendriveStarRating.FOUR;
eventRatings.hardBrakeRating = ZendriveStarRating.THREE;
eventRatings.speedingRating = ZendriveStarRating.TWO;
eventRatings.hardTurnRating = ZendriveStarRating.FOUR;
eventRatings.phoneHandlingRating = ZendriveStarRating.FOUR;
MockDrive.Builder builder = MockDrive.Builder.newAutoDrive(driveStartTimestamp, driveEndTimestamp).setWayPoints(waypoints).setAverageSpeed(20).setMaxSpeed(40).setDistanceMeters(100).setDriveType(ZendriveDriveType.DRIVE).setPhonePosition(PhonePosition.UNKNOWN).setUserMode(ZendriveUserMode.DRIVER).setEventRatings(eventRatings).setScore(54).addEventBuilder(aggressiveAccelerationEventBuilder).addEventBuilder(collisionEventBuilder).addEventBuilder(hardBrakeEventBuilder).addEventBuilder(speedingEventBuilder).addEventBuilder(phoneScreenInteractionEventBuilder).addEventBuilder(phoneHandlingEventBuilder).addEventBuilder(hardTurnEventBuilder).addEventBuilder(stopSignViolationEventBuilder);
MockDrive customMockDrive = builder.build();
return customMockDrive.simulate(context, 10);
}
use of com.zendrive.sdk.LocationPointWithTimestamp in project zendrive-sdk-android-sample by zendrive.
the class MapActivity method drawTripOnMap.
public void drawTripOnMap(final DriveInfo driveInfo) {
// draw trip details on map.
final List<LatLng> points = new ArrayList<>();
final LatLngBounds.Builder builder = new LatLngBounds.Builder();
for (LocationPointWithTimestamp pt : driveInfo.waypoints) {
LatLng latLng = new LatLng(pt.location.latitude, pt.location.longitude);
// Adding the taped point to the ArrayList
points.add(latLng);
builder.include(latLng);
}
final List<LatLng> extrapolatedWaypoints = getExtrapolatedLatLngPoints(driveInfo);
for (LatLng point : extrapolatedWaypoints) {
builder.include(point);
}
final LatLngBounds bounds = builder.build();
supportmapfragment.getMapAsync(gMap -> {
PolylineOptions polylineOptions = new PolylineOptions();
// Setting the color of the polyline
polylineOptions.color(Color.RED);
// Setting the width of the polyline
polylineOptions.width(10);
polylineOptions.addAll(points);
gMap.addPolyline(polylineOptions);
if (!extrapolatedWaypoints.isEmpty()) {
PolylineOptions extrapolatedPolylineOptions = new PolylineOptions();
extrapolatedPolylineOptions.color(Color.GRAY);
extrapolatedPolylineOptions.width(5);
extrapolatedPolylineOptions.addAll(extrapolatedWaypoints);
gMap.addPolyline(extrapolatedPolylineOptions);
}
int width = getResources().getDisplayMetrics().widthPixels;
int height = getResources().getDisplayMetrics().heightPixels;
// offset from edges of the map 13% of screen
int padding = (int) (0.13 * width);
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, width, height, padding);
gMap.animateCamera(cu);
// mark trip start and trip end.
if (!points.isEmpty()) {
LatLng tripStartLocation = points.get(0);
LatLng tripEndLocation = points.get(points.size() - 1);
markPoint(gMap, tripStartLocation, BitmapDescriptorFactory.HUE_GREEN, "Trip Start");
markPoint(gMap, tripEndLocation, BitmapDescriptorFactory.HUE_GREEN, "Trip End");
}
// mark the estimated trip start location
if (!extrapolatedWaypoints.isEmpty()) {
markPoint(gMap, extrapolatedWaypoints.get(0), BitmapDescriptorFactory.HUE_GREEN, "Estimated Trip Start");
}
// mark events.
markEvents(gMap, driveInfo.events);
});
}
Aggregations