Commit 9bfdc01c authored by Ratnadeep Rajendra Kharade's avatar Ratnadeep Rajendra Kharade
Browse files

Merge branch '71-prediction-ui-implementation-send-location-of-bike-to-backend' into 'master'

Resolve "Prediction UI implementation: Send location of bike to backend"

Closes #71

See merge request 92khra1mst/hft_awado_app!63
parents c8d646cb a36850ef
...@@ -113,4 +113,9 @@ ...@@ -113,4 +113,9 @@
</div> </div>
</div> </div>
</div> </div>
<!--div style="max-height: 100px; overflow-y: auto;">
<div *ngFor="let location of locationList;">
{{"sent height " + location.altitude}}
</div>
</div-->
</ion-footer> </ion-footer>
\ No newline at end of file
...@@ -47,7 +47,7 @@ export class HirebikePage implements OnInit { ...@@ -47,7 +47,7 @@ export class HirebikePage implements OnInit {
private defaultLayers: any; private defaultLayers: any;
private locationsGroup: any; private locationsGroup: any;
private currentUserPosition = { lat: 48.783480, lng: 9.180319 }; private currentUserPosition = { lat: 48.783480, lng: 9.180319, altitude: 250 };
private bikePosition = { lat: 48.783480, lng: 9.180319 }; private bikePosition = { lat: 48.783480, lng: 9.180319 };
private destinationPosition = { lat: 48.783480, lng: 9.180319 }; private destinationPosition = { lat: 48.783480, lng: 9.180319 };
...@@ -97,14 +97,20 @@ export class HirebikePage implements OnInit { ...@@ -97,14 +97,20 @@ export class HirebikePage implements OnInit {
} }
this.locationService.liveLocationSubject.subscribe((position) => { this.locationService.liveLocationSubject.subscribe((position) => {
console.log('got location inside home subscription'); console.log('got location inside my ride subscription');
console.log(position);
this.currentUserPosition.lat = position.lat; this.currentUserPosition.lat = position.lat;
this.currentUserPosition.lng = position.lng; this.currentUserPosition.lng = position.lng;
this.currentUserPosition.altitude = position.altitude;
if (this.currentLocationMarker) { if (this.currentLocationMarker) {
this.currentLocationMarker.setGeometry({ lat: this.currentUserPosition.lat, lng: this.currentUserPosition.lng }) this.currentLocationMarker.setGeometry({ lat: this.currentUserPosition.lat, lng: this.currentUserPosition.lng })
} else { } else {
this.showUserLocationOnMap(this.currentUserPosition.lat, this.currentUserPosition.lng); this.showUserLocationOnMap(this.currentUserPosition.lat, this.currentUserPosition.lng);
} }
// bike already rented
if(this.isTripStarted) {
this.map.setCenter({ lat: this.currentUserPosition.lat, lng: this.currentUserPosition.lng });
}
}); });
this.getReservedBike(); this.getReservedBike();
...@@ -437,30 +443,12 @@ export class HirebikePage implements OnInit { ...@@ -437,30 +443,12 @@ export class HirebikePage implements OnInit {
this.map.removeObject(this.noGoAreas); this.map.removeObject(this.noGoAreas);
} }
startTrip() { previousPositionObj:any = {};
this.isBikeHired = true; currentPositionObj:any = {};
this.startRideSubject.next('some value'); batteryLevelSentCount = 0;
this.loadingService.showLoader();
this.storage.get('token').then((token) => {
const bikeId = this.bikeDetails.id;
let url = 'http://193.196.52.237:8081/rent' + '?bikeId=' + this.bikeDetails.id;
const headers = new HttpHeaders().set("Authorization", "Bearer " + token);
let bikeApi = this.httpClient.get(url, { headers });
bikeApi.subscribe((resp) => {
console.log('my data: ', resp);
this.loadingService.hideLoader();
this.toastService.showToast("Trip Started");
this.isBikeHired = true;
}, (error) => {
console.log(error);
this.loadingService.hideLoader();
this.toastService.showToast("This is ongoing Trip");
});
});
}
intervalRef: any;
locationList = [];
startTrip2() { startTrip2() {
this.isBikeHired = true; this.isBikeHired = true;
this.isTripStarted = true; this.isTripStarted = true;
...@@ -473,10 +461,25 @@ export class HirebikePage implements OnInit { ...@@ -473,10 +461,25 @@ export class HirebikePage implements OnInit {
const headers = new HttpHeaders().set("Authorization", "Bearer " + token); const headers = new HttpHeaders().set("Authorization", "Bearer " + token);
let bikeApi = this.httpClient.get(url, { headers }); let bikeApi = this.httpClient.get(url, { headers });
bikeApi.subscribe((resp) => { bikeApi.subscribe((resp) => {
console.log('my data: ', resp); console.log('Trip Started: ', resp);
this.loadingService.hideLoader(); this.loadingService.hideLoader();
this.toastService.showToast("Trip Started"); this.toastService.showToast("Trip Started");
this.isBikeHired = true; this.isBikeHired = true;
this.currentPositionObj = {
lattitude: this.currentUserPosition.lat,
longitude: this.currentUserPosition.lng,
altitude: this.currentUserPosition.altitude,
}
if(this.batteryLevelSentCount === 0) {
this.previousPositionObj = this.currentPositionObj;
this.intervalRef = setInterval(() => {
this.sendUsageDataToBackend();
}, 20000);
} else {
this.intervalRef = setInterval(() => {
this.sendUsageDataToBackend();
}, 300000);
}
}, (error) => { }, (error) => {
console.log(error); console.log(error);
this.loadingService.hideLoader(); this.loadingService.hideLoader();
...@@ -486,11 +489,47 @@ export class HirebikePage implements OnInit { ...@@ -486,11 +489,47 @@ export class HirebikePage implements OnInit {
} }
// this function will draw route after start trip button is clicked
drawFinalRouteonMap() { drawFinalRouteonMap() {
this.map.removeObjects(this.map.getObjects()); this.map.removeObjects(this.map.getObjects());
this.addRouteShapeToMap(this.selectedRoute); this.addRouteShapeToMap(this.selectedRoute);
this.addManueversToMap(this.selectedRoute); this.addManueversToMap(this.selectedRoute);
this.mapDataService.mapDataSubject.next(this.selectedRoute); this.mapDataService.mapDataSubject.next(this.selectedRoute);
this.currentLocationMarker = null;
//get user location
if (this.currentLocationMarker) {
this.currentLocationMarker.setGeometry({ lat: this.currentUserPosition.lat, lng: this.currentUserPosition.lng })
} else {
this.showUserLocationOnMapForRouting(this.currentUserPosition.lat, this.currentUserPosition.lng);
}
}
//send bike usage data to backend every 2 minutes
sendUsageDataToBackend() {
this.storage.get('token').then((token) => {
let url = 'http://193.196.52.237:8081/batteryLevel';
const headers = new HttpHeaders().set("Authorization", "Bearer " + token);
let batteryLevelApi = this.httpClient.get<any>(url,{headers});
batteryLevelApi.subscribe((batteryResp) => {
console.log("Battery Level Response", batteryResp);
let url = 'http://193.196.52.237:8081/segment';
const headers = new HttpHeaders().set("Authorization", "Bearer " + token);
this.currentPositionObj.batteryLevel = batteryResp.data;
this.currentPositionObj.altitude = this.currentUserPosition.altitude;
let requestObject = {
previousPosition: this.previousPositionObj,
currentPosition: this.currentPositionObj
}
let usageDataApi = this.httpClient.post<any>(url, {requestObject}, {headers});
usageDataApi.subscribe((resp) => {
console.log("Usage api response", resp);
this.previousPositionObj = this.currentPositionObj;
this.batteryLevelSentCount++;
this.locationList.push(this.currentPositionObj);
}, (error) => console.log(error));
}, (error) => console.log(error));
});
} }
CancelTrip() { CancelTrip() {
...@@ -807,6 +846,20 @@ export class HirebikePage implements OnInit { ...@@ -807,6 +846,20 @@ export class HirebikePage implements OnInit {
//this.map.setCenter({ lat: lat, lng: lng }); //this.map.setCenter({ lat: lat, lng: lng });
} }
showUserLocationOnMapForRouting(lat, lng) {
let svgMarkup = '<svg width="24" height="24" ' +
'xmlns="http://www.w3.org/2000/svg">' +
'<circle cx="10" cy="10" r="10" ' +
'fill="#007cff" stroke="white" stroke-width="2" />' +
'</svg>';
let icon = new H.map.Icon(svgMarkup);
// Create a marker using the previously instantiated icon:
this.currentLocationMarker = new H.map.Marker({ lat: lat, lng: lng }, { icon: icon });
// Add the marker to the map:
this.map.addObject(this.currentLocationMarker);
this.map.setCenter({ lat: lat, lng: lng });
}
addMarker(lat, lng, img) { addMarker(lat, lng, img) {
var icon = new H.map.Icon(img); var icon = new H.map.Icon(img);
// Create a marker using the previously instantiated icon: // Create a marker using the previously instantiated icon:
...@@ -961,9 +1014,13 @@ export class HirebikePage implements OnInit { ...@@ -961,9 +1014,13 @@ export class HirebikePage implements OnInit {
} }
ionViewDidLeave() { ionViewDidLeave() {
console.log("Route: Ion View Left.")
if (this.mapElement) { if (this.mapElement) {
this.mapElement.nativeElement.remove(); this.mapElement.nativeElement.remove();
} }
if (this.intervalRef) {
clearInterval(this.intervalRef);
}
// if(this.locationService.liveLocationSubject) { // if(this.locationService.liveLocationSubject) {
// this.locationService.liveLocationSubject.unsubscribe(); // this.locationService.liveLocationSubject.unsubscribe();
// } // }
......
...@@ -5,24 +5,30 @@ import { Subject } from 'rxjs'; ...@@ -5,24 +5,30 @@ import { Subject } from 'rxjs';
providedIn: 'root' providedIn: 'root'
}) })
export class LocationService { export class LocationService {
public preiousUserPosition = { lat: 48.783480, lng: 9.180319 }; public preiousUserPosition = { lat: 48.783480, lng: 9.180319, altitude: 250};
public currentUserPosition = { lat: 48.783480, lng: 9.180319 }; public currentUserPosition = { lat: 48.783480, lng: 9.180319, altitude: 250};
liveLocationSubject = new Subject<any>(); //Decalring new RxJs Subject liveLocationSubject = new Subject<any>(); //Decalring new RxJs Subject
constructor(private geolocation: Geolocation) { constructor(private geolocation: Geolocation) {
let watch = this.geolocation.watchPosition({ enableHighAccuracy: true, maximumAge: 10000 }); let watch = this.geolocation.watchPosition({ enableHighAccuracy: true, maximumAge: 10000 });
watch.subscribe((position) => { watch.subscribe((position) => {
console.log('IN WATCHER') console.log(position);
console.log('lat'+ position.coords.latitude); let altitude = position.coords.altitude;
console.log('lng'+ position.coords.longitude); if (!altitude) {
altitude = 250;
}
this.currentUserPosition.lat = position.coords.latitude; this.currentUserPosition.lat = position.coords.latitude;
this.currentUserPosition.lng = position.coords.longitude; this.currentUserPosition.lng = position.coords.longitude;
this.currentUserPosition.altitude = altitude;
this.preiousUserPosition.lat = position.coords.latitude; this.preiousUserPosition.lat = position.coords.latitude;
this.preiousUserPosition.lng = position.coords.longitude; this.preiousUserPosition.lng = position.coords.longitude;
this.preiousUserPosition.altitude = altitude;
this.getUserLiveLocation(this.currentUserPosition); this.getUserLiveLocation(this.currentUserPosition);
}, (errorObj) => { }, (errorObj) => {
console.log('error getting live location, setting to previous location'); console.log('Error getting live location, setting to previous location');
this.getUserLiveLocation(this.preiousUserPosition); this.getUserLiveLocation(this.preiousUserPosition);
}); });
} }
...@@ -31,12 +37,21 @@ export class LocationService { ...@@ -31,12 +37,21 @@ export class LocationService {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.geolocation.getCurrentPosition().then((resp) => { this.geolocation.getCurrentPosition().then((resp) => {
console.log(resp);
let lat = resp.coords.latitude; let lat = resp.coords.latitude;
let lng = resp.coords.longitude; let lng = resp.coords.longitude;
let altitude = resp.coords.altitude;
if (!altitude) {
altitude = 250;
}
this.currentUserPosition.lat = resp.coords.latitude; this.currentUserPosition.lat = resp.coords.latitude;
this.currentUserPosition.lng = resp.coords.longitude; this.currentUserPosition.lng = resp.coords.longitude;
this.currentUserPosition.altitude = altitude;
this.preiousUserPosition.lat = resp.coords.latitude; this.preiousUserPosition.lat = resp.coords.latitude;
this.preiousUserPosition.lng = resp.coords.longitude; this.preiousUserPosition.lng = resp.coords.longitude;
this.preiousUserPosition.altitude = altitude;
resolve(this.currentUserPosition); resolve(this.currentUserPosition);
}, er => { }, er => {
console.log('error getting location setting to previous location'); console.log('error getting location setting to previous location');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment