Commit 791f17d0 by Alen Jose

Merge branch 'alen' into 'master'

live location See merge request alen/CMC-driver!15
parents 6b38da01 082174de
...@@ -11,6 +11,7 @@ import { driver } from "../models/mymodel"; ...@@ -11,6 +11,7 @@ import { driver } from "../models/mymodel";
import * as firebase from 'firebase'; import * as firebase from 'firebase';
import { LocalNotifications } from '@ionic-native/local-notifications'; import { LocalNotifications } from '@ionic-native/local-notifications';
import { dataService } from "../providers/common.service"; import { dataService } from "../providers/common.service";
import { Geolocation } from '@ionic-native/geolocation';
@Component({ @Component({
templateUrl: 'app.html' templateUrl: 'app.html'
...@@ -25,8 +26,9 @@ export class MyApp { ...@@ -25,8 +26,9 @@ export class MyApp {
local: driver local: driver
status: boolean status: boolean
pushId: string pushId: string
locSubs: any;
constructor(public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen, private network: Network, private alertCtrl: AlertController, private oneSignal: OneSignal, private locationAccuracy: LocationAccuracy, private storage: Storage, private myservice: Myservice, public events: Events, private localNotifications: LocalNotifications, private data: dataService) { constructor(public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen, private network: Network, private alertCtrl: AlertController, private oneSignal: OneSignal, private locationAccuracy: LocationAccuracy, private storage: Storage, private myservice: Myservice, public events: Events, private localNotifications: LocalNotifications, private data: dataService, private geolocation: Geolocation) {
this.initializeApp(); this.initializeApp();
} }
...@@ -35,8 +37,8 @@ export class MyApp { ...@@ -35,8 +37,8 @@ export class MyApp {
this.platform.ready().then(() => { this.platform.ready().then(() => {
this.statusBar.styleLightContent(); this.statusBar.styleLightContent();
this.initOnesignal(); // this.initOnesignal();
this.enableLoc() // this.enableLoc()
this.network.onDisconnect().subscribe(() => { this.network.onDisconnect().subscribe(() => {
const alert = this.alertCtrl.create({ const alert = this.alertCtrl.create({
...@@ -66,6 +68,14 @@ export class MyApp { ...@@ -66,6 +68,14 @@ export class MyApp {
} }
}) })
this.events.subscribe('driver:locOff',_=>{
this.locSubs.unsubscribe();
})
this.events.subscribe('driver:locOn',_=>{
this.liveLoc();
})
this.storage.get('driver_data').then(data => { this.storage.get('driver_data').then(data => {
if (data != null) { if (data != null) {
this.local = data this.local = data
...@@ -90,12 +100,13 @@ export class MyApp { ...@@ -90,12 +100,13 @@ export class MyApp {
} }
checkStatus() { checkStatus() {
this.oneSignal.getIds().then((id) => { // this.oneSignal.getIds().then((id) => {
console.log(id.userId) // console.log(id.userId)
this.myservice.load_post({deviceid:id.userId,driverid:this.local.id},'updateDeviceid').subscribe(resp=>{ // this.myservice.load_post({deviceid:id.userId,driverid:this.local.id},'updateDeviceid').subscribe(resp=>{
console.log(resp) // console.log(resp)
}) // })
}) // })
console.log(this.local)
var This = this var This = this
var query = firebase.database().ref("drivers/").orderByChild("id").equalTo((this.local.id)) var query = firebase.database().ref("drivers/").orderByChild("id").equalTo((this.local.id))
query.once("child_added", function (snapshot) { query.once("child_added", function (snapshot) {
...@@ -122,7 +133,7 @@ export class MyApp { ...@@ -122,7 +133,7 @@ export class MyApp {
} }
}) })
},20000) },20000)
This.setlocalNotification(); // This.setlocalNotification();
} }
openPage(page) { openPage(page) {
...@@ -202,4 +213,13 @@ export class MyApp { ...@@ -202,4 +213,13 @@ export class MyApp {
}) })
} }
liveLoc(){
this.locSubs = this.geolocation.watchPosition().filter((p) => p.coords !== undefined) //Filter Out Errors
.subscribe(position => {
firebase.database().ref("drivers/" + this.pushId + "/").update({ lat: Number(position.coords.latitude), lng: Number(position.coords.longitude) })
// firebase.database().ref("drivers/" + this.pushId + "/").update({
// lat: 10.014907, lng: 76.363020})
})
}
} }
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular'; import { IonicPage, NavController, NavParams,Events } from 'ionic-angular';
import { Storage } from "@ionic/storage"; import { Storage } from "@ionic/storage";
import { Myservice } from "../../providers/myservice"; import { Myservice } from "../../providers/myservice";
import { dataService } from "../../providers/common.service"; import { dataService } from "../../providers/common.service";
...@@ -15,10 +15,13 @@ upcoming:any; ...@@ -15,10 +15,13 @@ upcoming:any;
completed:any; completed:any;
baseurl = this.myservice.base_url baseurl = this.myservice.base_url
constructor(public navCtrl: NavController, public navParams: NavParams, private storage: Storage, private myservice: Myservice, private data: dataService) { constructor(public navCtrl: NavController, public navParams: NavParams, private storage: Storage, private myservice: Myservice, private data: dataService, public events: Events) {
} }
ionViewDidEnter(){ ionViewDidEnter(){
this.events.publish('driver:locOn', '');
if (this.navParams.get('id')) if (this.navParams.get('id'))
this.navCtrl.push('QuickridePage', { id: this.navParams.get('id'), from: this.navParams.get('from') }) this.navCtrl.push('QuickridePage', { id: this.navParams.get('id'), from: this.navParams.get('from') })
......
import { Component, ViewChild, ElementRef } from '@angular/core'; import { Component, ViewChild, ElementRef } from '@angular/core';
import { IonicPage, NavController, NavParams, MenuController } from 'ionic-angular'; import { IonicPage, NavController, NavParams, MenuController, Events } from 'ionic-angular';
import { Geolocation } from '@ionic-native/geolocation'; import { Geolocation } from '@ionic-native/geolocation';
import * as firebase from 'firebase'; import * as firebase from 'firebase';
import { AngularFireDatabase } from 'angularfire2/database'; import { AngularFireDatabase } from 'angularfire2/database';
...@@ -31,12 +31,14 @@ export class UserlocationPage { ...@@ -31,12 +31,14 @@ export class UserlocationPage {
waypoints = [] waypoints = []
ride:any; ride:any;
constructor(public navCtrl: NavController, public navParams: NavParams, private geolocation: Geolocation, private db: AngularFireDatabase, private storage: Storage, private myservice: Myservice, private menu: MenuController, private data: dataService) { constructor(public navCtrl: NavController, public navParams: NavParams, private geolocation: Geolocation, private db: AngularFireDatabase, private storage: Storage, private myservice: Myservice, private menu: MenuController, private data: dataService, public events: Events) {
this.loadMap() this.loadMap()
} }
ionViewDidEnter() { ionViewDidEnter() {
this.events.publish('driver:locOff', '');
this.menu.swipeEnable(false); this.menu.swipeEnable(false);
......
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