diff --git a/src/app/hirebike/hirebike.page.html b/src/app/hirebike/hirebike.page.html index 972dc2f2580e5f6eae655ae729b93f53833e86c8..ab90ca4692a3b1469531954178ffa3adcef28b79 100644 --- a/src/app/hirebike/hirebike.page.html +++ b/src/app/hirebike/hirebike.page.html @@ -31,7 +31,7 @@ </ion-row> <ion-row> <ion-col>Bike Location</ion-col> - <ion-col>{{bikeDetails.address}}</ion-col> + <ion-col>{{address}}</ion-col> </ion-row> <ion-row *ngIf="!isBikeHired"> <ion-col> diff --git a/src/app/hirebike/hirebike.page.ts b/src/app/hirebike/hirebike.page.ts index f92752c3bac8ae2fd38cc38b0bd2ce896f9a9997..c7f2d5e230a38872ce4fb881601a8172453ab708 100644 --- a/src/app/hirebike/hirebike.page.ts +++ b/src/app/hirebike/hirebike.page.ts @@ -22,6 +22,7 @@ export class HirebikePage implements OnInit { reservedBike: any = {}; bikeDetails: any = {}; + address="sample"; isBikeHired=false; noReservation = true; @@ -82,7 +83,7 @@ export class HirebikePage implements OnInit { console.log('Bike Details', resp); this.bikeDetails = resp.data; this.noReservation = false; - + this.reverseGeocode(this.platform, this.bikeDetails.lat, this.bikeDetails.lon); // display map setTimeout(() => { this.loadmap(); @@ -230,7 +231,29 @@ export class HirebikePage implements OnInit { // Add the marker to the map: this.map.addObject(marker); } - + reverseGeocode(platform, lat, lng) { + var prox = lat + ',' + lng + ',56'; + var geocoder = platform.getGeocodingService(), + parameters = { + prox: prox, + mode: 'retrieveAddresses', + maxresults: '1', + gen: '9' + }; + + geocoder.reverseGeocode(parameters, result => { + console.log(result); + var streets = result.Response.View[0].Result[0].Location.Address.Street; + var houseNumber = result.Response.View[0].Result[0].Location.Address.HouseNumber; + var zipcode = result.Response.View[0].Result[0].Location.Address.PostalCode; + + this.address = streets; + + + }, (error) => { + alert(error); + }); + } // Define a callback function to process the routing response: onResult(result) { diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts index 21af6c44bdd7780fa5a8b8026627bc844968fe7e..1ac7d8e67f9f969d8ea0d45eea16f6ec1562ad40 100644 --- a/src/app/home/home.page.ts +++ b/src/app/home/home.page.ts @@ -5,7 +5,7 @@ import { Observable } from 'rxjs'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Storage } from '@ionic/storage'; import { ToastService } from '../services/toast.service'; - +import { Router } from '@angular/router'; declare var H: any; @@ -46,6 +46,7 @@ export class HomePage { constructor(private geolocation: Geolocation, + private router: Router, public restService: RestService, public httpClient: HttpClient, private storage: Storage, @@ -275,6 +276,7 @@ export class HomePage { console.log('my data: ', resp); this.isBikeReserved=true; this.toastService.showToast("Reservation Successful!"); + this.router.navigateByUrl('/myreservation'); }, (error) => { console.log(error) this.toastService.showToast("Only one bike may be reserved or rented at a time") diff --git a/src/app/myreservation/myreservation.page.html b/src/app/myreservation/myreservation.page.html index 76a54fc513bcac7766a7718eaa9a00f1121d6f5d..341a202a6357ecb6e2ba3cd924f9754ddf036445 100644 --- a/src/app/myreservation/myreservation.page.html +++ b/src/app/myreservation/myreservation.page.html @@ -36,7 +36,7 @@ </ion-row> <ion-row> <ion-col>Bike Location</ion-col> - <ion-col>{{bikeDetails.address}}</ion-col> + <ion-col>{{address}}</ion-col> </ion-row> <ion-row> <ion-col>Bike Distance</ion-col> diff --git a/src/app/myreservation/myreservation.page.ts b/src/app/myreservation/myreservation.page.ts index 3631d511a685ff047d311b292e09509ece8357b6..d81b096fa9a59983fecf134bc8c8da174318f18b 100644 --- a/src/app/myreservation/myreservation.page.ts +++ b/src/app/myreservation/myreservation.page.ts @@ -23,8 +23,8 @@ export class MyreservationPage implements OnInit { reservedBike: any = {}; bikeDetails: any = {}; - isBikeHired=false; - + isBikeHired = false; + address="sample"; noReservation = true; private currentLocation = { lat: 0, lng: 0 }; @@ -82,6 +82,7 @@ export class MyreservationPage implements OnInit { bikeDetailsApi.subscribe((resp: any) => { console.log('Bike Details', resp); this.bikeDetails = resp.data; + this.reverseGeocode(this.platform, this.bikeDetails.lat, this.bikeDetails.lon); this.noReservation = false; // display map @@ -183,9 +184,9 @@ export class MyreservationPage implements OnInit { // show route on map this.mapRouter.calculateRoute(this.routingParameters, this.onResult.bind(this), - (error) => { - alert(error.message); - }); + (error) => { + alert(error.message); + }); }, er => { alert('Can not retrieve Location') }).catch((error) => { @@ -209,6 +210,29 @@ export class MyreservationPage implements OnInit { // Add the marker to the map: this.map.addObject(marker); } + reverseGeocode(platform, lat, lng) { + var prox = lat + ',' + lng + ',56'; + var geocoder = platform.getGeocodingService(), + parameters = { + prox: prox, + mode: 'retrieveAddresses', + maxresults: '1', + gen: '9' + }; + + geocoder.reverseGeocode(parameters, result => { + console.log(result); + var streets = result.Response.View[0].Result[0].Location.Address.Street; + var houseNumber = result.Response.View[0].Result[0].Location.Address.HouseNumber; + var zipcode = result.Response.View[0].Result[0].Location.Address.PostalCode; + + this.address = streets; + + + }, (error) => { + alert(error); + }); + } // Define a callback function to process the routing response: @@ -251,7 +275,7 @@ export class MyreservationPage implements OnInit { lineWidth: 6, strokeColor: 'rgba(0, 72, 255, 0.8)', lineDash: [0, 2] - } + } }); // Add the route polyline and the two markers to the map: @@ -262,10 +286,11 @@ export class MyreservationPage implements OnInit { //this.map.setZoom(this.map.getZoom() - 4.3, true); } }; + hireBike() { if (this.isBikeHired) - this.toastService.showToast("You already Hired this bike"); + this.toastService.showToast("You already Hired this bike"); else - this.router.navigateByUrl('/hirebike'); + this.router.navigateByUrl('/hirebike'); } }