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";
import * as firebase from 'firebase';
import { LocalNotifications } from '@ionic-native/local-notifications';
import { dataService } from "../providers/common.service";
import { Geolocation } from '@ionic-native/geolocation';
@Component({
templateUrl: 'app.html'
......@@ -25,8 +26,9 @@ export class MyApp {
local: driver
status: boolean
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();
}
......@@ -35,8 +37,8 @@ export class MyApp {
this.platform.ready().then(() => {
this.statusBar.styleLightContent();
this.initOnesignal();
this.enableLoc()
// this.initOnesignal();
// this.enableLoc()
this.network.onDisconnect().subscribe(() => {
const alert = this.alertCtrl.create({
......@@ -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 => {
if (data != null) {
this.local = data
......@@ -90,12 +100,13 @@ export class MyApp {
}
checkStatus() {
this.oneSignal.getIds().then((id) => {
console.log(id.userId)
this.myservice.load_post({deviceid:id.userId,driverid:this.local.id},'updateDeviceid').subscribe(resp=>{
console.log(resp)
})
})
// this.oneSignal.getIds().then((id) => {
// console.log(id.userId)
// this.myservice.load_post({deviceid:id.userId,driverid:this.local.id},'updateDeviceid').subscribe(resp=>{
// console.log(resp)
// })
// })
console.log(this.local)
var This = this
var query = firebase.database().ref("drivers/").orderByChild("id").equalTo((this.local.id))
query.once("child_added", function (snapshot) {
......@@ -122,7 +133,7 @@ export class MyApp {
}
})
},20000)
This.setlocalNotification();
// This.setlocalNotification();
}
openPage(page) {
......@@ -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 { IonicPage, NavController, NavParams } from 'ionic-angular';
import { IonicPage, NavController, NavParams,Events } from 'ionic-angular';
import { Storage } from "@ionic/storage";
import { Myservice } from "../../providers/myservice";
import { dataService } from "../../providers/common.service";
......@@ -15,10 +15,13 @@ upcoming:any;
completed:any;
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(){
this.events.publish('driver:locOn', '');
if (this.navParams.get('id'))
this.navCtrl.push('QuickridePage', { id: this.navParams.get('id'), from: this.navParams.get('from') })
......
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 * as firebase from 'firebase';
import { AngularFireDatabase } from 'angularfire2/database';
......@@ -31,12 +31,14 @@ export class UserlocationPage {
waypoints = []
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()
}
ionViewDidEnter() {
this.events.publish('driver:locOff', '');
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