Replace single get Google address API to Bulk get address API and Create Local cache for address
This commit is contained in:
parent
63d062c4a7
commit
e24269c2a5
8 changed files with 2781 additions and 2566 deletions
|
|
@ -112,7 +112,7 @@ console.log(token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.contactService.dealerInfo(this.url == 'localhost:4200' ?'oneqlik.in':this.url ).subscribe(
|
this.contactService.dealerInfo(this.url == 'localhost:4200' ?'www.oneqlik.in':this.url ).subscribe(
|
||||||
data => {
|
data => {
|
||||||
this.userData = data
|
this.userData = data
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ import { map, take } from 'rxjs/operators';
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ContactService {
|
export class ContactService {
|
||||||
totalTicketCount:BehaviorSubject<number> = new BehaviorSubject<number>(10);
|
totalTicketCount:BehaviorSubject<number> = new BehaviorSubject<number>(10);
|
||||||
|
latLongAddress={};
|
||||||
dev_url = environment.hostUrl;
|
dev_url = environment.hostUrl;
|
||||||
dev_url2= environment.hostUrl2
|
dev_url2= environment.hostUrl2
|
||||||
//dev_url = 'http://localhost:3000';
|
//dev_url = 'http://localhost:3000';
|
||||||
|
|
@ -438,7 +438,7 @@ getCurrentLocation(id,from,to){
|
||||||
getCurrentLocation1(id,from,to,satelite){
|
getCurrentLocation1(id,from,to,satelite){
|
||||||
if(satelite==undefined){
|
if(satelite==undefined){
|
||||||
return this.http.get(this.dev_url + '/gps?id='+id+'&from='+from+'&to='+to)
|
return this.http.get(this.dev_url + '/gps?id='+id+'&from='+from+'&to='+to)
|
||||||
.map(res => res.json());
|
.map(res => res.json());
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
return this.http.get(this.dev_url + '/gps?id='+id+'&from='+from+'&to='+to+'&satelite='+satelite)
|
return this.http.get(this.dev_url + '/gps?id='+id+'&from='+from+'&to='+to+'&satelite='+satelite)
|
||||||
|
|
@ -1637,7 +1637,6 @@ addPOICol(poipayload){
|
||||||
.map(res => res.json());
|
.map(res => res.json());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
setlanguage(payload){
|
setlanguage(payload){
|
||||||
return this.http.post(this.dev_url +'/users/set_user_setting',payload)
|
return this.http.post(this.dev_url +'/users/set_user_setting',payload)
|
||||||
.map(res => res.json());
|
.map(res => res.json());
|
||||||
|
|
@ -1650,8 +1649,19 @@ getLanguages(payload){
|
||||||
|
|
||||||
|
|
||||||
getAddressByApi(latlng){
|
getAddressByApi(latlng){
|
||||||
|
if(this.latLongAddress[latlng.long+'_'+latlng.lat]) {
|
||||||
|
console.log('get address for cache');
|
||||||
|
return Observable.of(this.latLongAddress[latlng.long+'_'+latlng.lat]);
|
||||||
|
} else {
|
||||||
|
return this.http.post(this.dev_url +'/googleAddress/getGoogleAddress',latlng)
|
||||||
|
.map(res => res.json());
|
||||||
|
}
|
||||||
|
|
||||||
return this.http.post(this.dev_url +'/googleAddress/getGoogleAddress',latlng)
|
|
||||||
|
}
|
||||||
|
getAddressByApiBulk(latlng){
|
||||||
|
|
||||||
|
return this.http.post(this.dev_url +'/googleAddress/getGoogleAddressBulk',latlng)
|
||||||
.map(res => res.json());
|
.map(res => res.json());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -580,25 +580,43 @@ testTable() {
|
||||||
if (that.reportArr.length != 0) {
|
if (that.reportArr.length != 0) {
|
||||||
var j = 0;
|
var j = 0;
|
||||||
var finalArr = [];
|
var finalArr = [];
|
||||||
for (var i = 0; i < that.reportArr.length; i++) {
|
|
||||||
|
let latLongArray :any[] = [];
|
||||||
that.clocation_1(that.reportArr[i], function (err, succ) {
|
that.reportArr.forEach((deData)=>{
|
||||||
if (err) {
|
let latLng = {
|
||||||
console.log(err);
|
lat: deData.startLat ? deData.startLat : 0,
|
||||||
j++;
|
long: deData.startLng ? deData.startLng : 0
|
||||||
} else {
|
}
|
||||||
finalArr.push(succ);
|
latLongArray.push(latLng)
|
||||||
console.log(finalArr);
|
})
|
||||||
j++;
|
|
||||||
if (j === that.reportArr.length) {
|
that.contactService.getAddressByApiBulk(latLongArray).subscribe(latLongAddress => {
|
||||||
that.Load = false;
|
that.reportArr.forEach((deData,index)=>{
|
||||||
callback({ data: finalArr });
|
let latLng = {
|
||||||
}
|
lat: deData.startLat ? deData.startLat : 0,
|
||||||
|
long: deData.startLng ? deData.startLng : 0
|
||||||
}
|
}
|
||||||
|
that.contactService.latLongAddress[latLng.long+'_'+latLng.lat] = latLongAddress[index];
|
||||||
|
that.clocation_1(deData, function (err, succ) {
|
||||||
|
if (err) {
|
||||||
|
console.log(err);
|
||||||
|
j++;
|
||||||
|
} else {
|
||||||
|
finalArr.push(succ);
|
||||||
|
console.log(finalArr);
|
||||||
|
j++;
|
||||||
|
if (j === that.reportArr.length) {
|
||||||
|
that.Load = false;
|
||||||
|
callback({ data: finalArr });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
})
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
that.Load = false;
|
that.Load = false;
|
||||||
that.firstcall=true;
|
that.firstcall=true;
|
||||||
|
|
@ -792,13 +810,6 @@ tab:any;
|
||||||
long: latlngObj.startLng ? latlngObj.startLng : 0
|
long: latlngObj.startLng ? latlngObj.startLng : 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// if () {
|
|
||||||
// latLng = {
|
|
||||||
// lat: 0,
|
|
||||||
// long: 0
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
outerThis.contactService.getAddressByApi(latLng).subscribe(res => {
|
outerThis.contactService.getAddressByApi(latLng).subscribe(res => {
|
||||||
if (res.message == "Address not found in databse") {
|
if (res.message == "Address not found in databse") {
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -325,82 +325,115 @@ export class CurrentPositionReportComponent implements OnInit {
|
||||||
if (that.reportArr.length != 0) {
|
if (that.reportArr.length != 0) {
|
||||||
var j = 0;
|
var j = 0;
|
||||||
that.finalArr = [];
|
that.finalArr = [];
|
||||||
for (var i = 0; i < that.reportArr.length; i++) {
|
|
||||||
if (that.reportArr[i]) {
|
|
||||||
|
|
||||||
if (that.reportArr[i].status_updated_at == undefined) {
|
let latLongArray :any[] = [];
|
||||||
let dev_status_1 = that.reportArr[i].status ? that.reportArr[i].status : "Not available";
|
that.reportArr.forEach((deData)=>{
|
||||||
that.reportArr[i].status = dev_status_1;
|
|
||||||
// console.log("Not Available !!!");
|
|
||||||
} else {
|
|
||||||
// this.arrival_time = new Date(that.reportArr[i].status_updated_at)
|
|
||||||
let dev_status = that.reportArr[i] ? that.reportArr[i].status : "NA";
|
|
||||||
var curr_time: any = new Date();
|
|
||||||
this.arrival_time = new Date(that.reportArr[i].status_updated_at);
|
|
||||||
var fd: any = new Date(this.arrival_time);
|
|
||||||
// console.log('curr_time',curr_time,this.arrival_time);
|
|
||||||
var diffInMilliSeconds = Math.abs(curr_time - fd) / 1000;
|
|
||||||
|
|
||||||
// calculate days
|
let latLng = {
|
||||||
const days = Math.floor(diffInMilliSeconds / 86400);
|
lat: "0",
|
||||||
diffInMilliSeconds -= days * 86400;
|
long: "0"
|
||||||
// console.log('calculated days', days);
|
};
|
||||||
|
|
||||||
// calculate hours
|
latLng = {
|
||||||
const hours = Math.floor(diffInMilliSeconds / 3600) % 24;
|
long: deData.last_loc && deData.last_loc.coordinates && deData.last_loc.coordinates.length && deData.last_loc.coordinates[0] ? deData.last_loc.coordinates[0] : 0,
|
||||||
diffInMilliSeconds -= hours * 3600;
|
lat: deData.last_loc && deData.last_loc.coordinates && deData.last_loc.coordinates.length && deData.last_loc.coordinates[1] ? deData.last_loc.coordinates[1]: 0
|
||||||
// console.log('calculated hours', hours);
|
|
||||||
|
|
||||||
// calculate minutes
|
|
||||||
const minutes = Math.floor(diffInMilliSeconds / 60) % 60;
|
|
||||||
diffInMilliSeconds -= minutes * 60;
|
|
||||||
// console.log('minutes', minutes);
|
|
||||||
|
|
||||||
let difference = '';
|
|
||||||
if (days > 0) {
|
|
||||||
difference += (days === 1) ? `${days} day, ` : `${days} days, `;
|
|
||||||
}
|
|
||||||
|
|
||||||
difference += (hours === 0 || hours === 1) ? `${hours} hour, ` : `${hours} hours, `;
|
|
||||||
|
|
||||||
difference += (minutes === 0 || hours === 1) ? `${minutes} minutes` : `${minutes} minutes`;
|
|
||||||
|
|
||||||
// new conversion logic
|
|
||||||
this.Durations = difference;
|
|
||||||
if (dev_status == undefined) {
|
|
||||||
|
|
||||||
this.status_toShow = "NA";
|
|
||||||
|
|
||||||
} else {
|
|
||||||
this.status_toShow = dev_status + " " + "Since" + " " + this.Durations;
|
|
||||||
}
|
|
||||||
|
|
||||||
that.reportArr[i].status = this.status_toShow;
|
|
||||||
}
|
|
||||||
|
|
||||||
that.clocation_1(that.reportArr[i], function (err, succ) {
|
|
||||||
if (err) {
|
|
||||||
console.log(err);
|
|
||||||
j++;
|
|
||||||
} else {
|
|
||||||
console.log(succ);
|
|
||||||
that.finalArr.push(succ);
|
|
||||||
console.log(that.finalArr);
|
|
||||||
j++;
|
|
||||||
if (j === that.reportArr.length) {
|
|
||||||
that.Load = false;
|
|
||||||
callback({ data: that.finalArr });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
that.Load = false;
|
|
||||||
callback({ data: [] });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
latLongArray.push(latLng)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
that.contactService.getAddressByApiBulk(latLongArray).subscribe(latLongAddress => {
|
||||||
|
|
||||||
|
|
||||||
|
for (var i = 0; i < that.reportArr.length; i++) {
|
||||||
|
|
||||||
|
if (that.reportArr[i]) {
|
||||||
|
let latLng = {
|
||||||
|
lat: "0",
|
||||||
|
long: "0"
|
||||||
|
};
|
||||||
|
latLng = {
|
||||||
|
long: that.reportArr[i].last_loc && that.reportArr[i].last_loc.coordinates && that.reportArr[i].last_loc.coordinates.length && that.reportArr[i].last_loc.coordinates[0] ? that.reportArr[i].last_loc.coordinates[0] : 0,
|
||||||
|
lat: that.reportArr[i].last_loc && that.reportArr[i].last_loc.coordinates && that.reportArr[i].last_loc.coordinates.length && that.reportArr[i].last_loc.coordinates[1] ? that.reportArr[i].last_loc.coordinates[1]: 0
|
||||||
|
}
|
||||||
|
that.contactService.latLongAddress[latLng.long+'_'+latLng.lat] = latLongAddress[i];
|
||||||
|
if (that.reportArr[i].status_updated_at == undefined) {
|
||||||
|
let dev_status_1 = that.reportArr[i].status ? that.reportArr[i].status : "Not available";
|
||||||
|
that.reportArr[i].status = dev_status_1;
|
||||||
|
// console.log("Not Available !!!");
|
||||||
|
} else {
|
||||||
|
// this.arrival_time = new Date(that.reportArr[i].status_updated_at)
|
||||||
|
let dev_status = that.reportArr[i] ? that.reportArr[i].status : "NA";
|
||||||
|
var curr_time: any = new Date();
|
||||||
|
this.arrival_time = new Date(that.reportArr[i].status_updated_at);
|
||||||
|
var fd: any = new Date(this.arrival_time);
|
||||||
|
// console.log('curr_time',curr_time,this.arrival_time);
|
||||||
|
var diffInMilliSeconds = Math.abs(curr_time - fd) / 1000;
|
||||||
|
|
||||||
|
// calculate days
|
||||||
|
const days = Math.floor(diffInMilliSeconds / 86400);
|
||||||
|
diffInMilliSeconds -= days * 86400;
|
||||||
|
// console.log('calculated days', days);
|
||||||
|
|
||||||
|
// calculate hours
|
||||||
|
const hours = Math.floor(diffInMilliSeconds / 3600) % 24;
|
||||||
|
diffInMilliSeconds -= hours * 3600;
|
||||||
|
// console.log('calculated hours', hours);
|
||||||
|
|
||||||
|
// calculate minutes
|
||||||
|
const minutes = Math.floor(diffInMilliSeconds / 60) % 60;
|
||||||
|
diffInMilliSeconds -= minutes * 60;
|
||||||
|
// console.log('minutes', minutes);
|
||||||
|
|
||||||
|
let difference = '';
|
||||||
|
if (days > 0) {
|
||||||
|
difference += (days === 1) ? `${days} day, ` : `${days} days, `;
|
||||||
|
}
|
||||||
|
|
||||||
|
difference += (hours === 0 || hours === 1) ? `${hours} hour, ` : `${hours} hours, `;
|
||||||
|
|
||||||
|
difference += (minutes === 0 || hours === 1) ? `${minutes} minutes` : `${minutes} minutes`;
|
||||||
|
|
||||||
|
// new conversion logic
|
||||||
|
this.Durations = difference;
|
||||||
|
if (dev_status == undefined) {
|
||||||
|
|
||||||
|
this.status_toShow = "NA";
|
||||||
|
|
||||||
|
} else {
|
||||||
|
this.status_toShow = dev_status + " " + "Since" + " " + this.Durations;
|
||||||
|
}
|
||||||
|
|
||||||
|
that.reportArr[i].status = this.status_toShow;
|
||||||
|
}
|
||||||
|
|
||||||
|
that.clocation_1(that.reportArr[i], function (err, succ) {
|
||||||
|
if (err) {
|
||||||
|
console.log(err);
|
||||||
|
j++;
|
||||||
|
} else {
|
||||||
|
console.log(succ);
|
||||||
|
that.finalArr.push(succ);
|
||||||
|
console.log(that.finalArr);
|
||||||
|
j++;
|
||||||
|
if (j === that.reportArr.length) {
|
||||||
|
that.Load = false;
|
||||||
|
callback({ data: that.finalArr });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
that.Load = false;
|
||||||
|
callback({ data: [] });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
})
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
that.Load = false;
|
that.Load = false;
|
||||||
that.firstcall = true;
|
that.firstcall = true;
|
||||||
|
|
|
||||||
|
|
@ -210,74 +210,93 @@ export class DayWiseReportComponent implements OnInit {
|
||||||
that.reportArr = [];
|
that.reportArr = [];
|
||||||
that.reportArr= resp ;
|
that.reportArr= resp ;
|
||||||
if (that.reportArr.length != 0) {
|
if (that.reportArr.length != 0) {
|
||||||
console.log(that.reportArr);
|
|
||||||
var j = 0;
|
var j = 0;
|
||||||
that.finalArr = [];
|
that.finalArr = [];
|
||||||
for (var i = 0; i < that.reportArr.length; i++) {
|
|
||||||
|
|
||||||
// if(that.reportArr[i].distanceVariation){
|
let latLongArray :any[] = [];
|
||||||
// console.log("IN");
|
that.reportArr.forEach((deData)=>{
|
||||||
|
let latLng = {
|
||||||
// if(that.reportArr[i].distanceVariation[0]=="+"){
|
lat: deData.start_location ? deData.start_location.lat ? deData.start_location.lat : 0:0,
|
||||||
// that.reportArr[i]['Distance(Kms)']=that.reportArr[i]['Distance(Kms)']+(that.reportArr[i]['Distance(Kms)']/100)*Number(that.reportArr[i].distanceVariation.substring(1))
|
long: deData.start_location ? deData.start_location.long ? deData.start_location.long : 0:0
|
||||||
// console.log("IN",(that.reportArr[i]['Distance(Kms)']/100)*Number(that.reportArr[i].distanceVariation.substring(1)));
|
}
|
||||||
// }else{
|
latLongArray.push(latLng)
|
||||||
|
let end_latLng = {
|
||||||
// that.reportArr[i]['Distance(Kms)']=that.reportArr[i]['Distance(Kms)']-(that.reportArr[i]['Distance(Kms)']/100)*Number(that.reportArr[i].distanceVariation.substring(1))
|
lat: deData.end_location ? deData.end_location.lat ? deData.end_location.lat : 0:0,
|
||||||
// console.log("IN-",that.reportArr[i]['Distance(Kms)']);
|
long: deData.end_location ? deData.end_location.long ? deData.end_location.long : 0:0
|
||||||
// }
|
}
|
||||||
// }
|
latLongArray.push(end_latLng)
|
||||||
|
})
|
||||||
console.log(that.reportArr[i]['Idle Time'],that.reportArr[i]['Moving Time'],that.reportArr[i]['Stoppage Time'],that.reportArr[i]['Idle Time']);
|
|
||||||
|
|
||||||
if((that.reportArr[i]['Idle Time']+that.reportArr[i]['Stoppage Time']+that.reportArr[i]['Moving Time'])<24){
|
that.contactService.getAddressByApiBulk(latLongArray).subscribe(latLongAddress => {
|
||||||
that.reportArr[i].outOfReach=(24-(that.reportArr[i]['Idle Time']+that.reportArr[i]['Stoppage Time']+that.reportArr[i]['Moving Time'])).toFixed(2)
|
let indexCounter = 0;
|
||||||
}else{
|
for (var i = 0; i < that.reportArr.length; i++) {
|
||||||
that.reportArr[i].outOfReach=0.0
|
let latLng = {
|
||||||
|
lat: that.reportArr[i].start_location ? that.reportArr[i].start_location.lat ? that.reportArr[i].start_location.lat : 0:0,
|
||||||
|
long: that.reportArr[i].start_location ? that.reportArr[i].start_location.long ? that.reportArr[i].start_location.long : 0:0
|
||||||
|
}
|
||||||
|
that.contactService.latLongAddress[latLng.long+'_'+latLng.lat] = latLongAddress[indexCounter];
|
||||||
|
indexCounter++;
|
||||||
|
let end_latLng = {
|
||||||
|
lat: that.reportArr[i].end_location ? that.reportArr[i].end_location.lat ? that.reportArr[i].end_location.lat : 0:0,
|
||||||
|
long: that.reportArr[i].end_location ? that.reportArr[i].end_location.long ? that.reportArr[i].end_location.long : 0:0
|
||||||
|
}
|
||||||
|
that.contactService.latLongAddress[end_latLng.long+'_'+end_latLng.lat] = latLongAddress[indexCounter];
|
||||||
|
console.log('indexCounter++',indexCounter,i)
|
||||||
|
indexCounter++;
|
||||||
|
|
||||||
}
|
if((that.reportArr[i]['Idle Time']+that.reportArr[i]['Stoppage Time']+that.reportArr[i]['Moving Time'])<24){
|
||||||
|
that.reportArr[i].outOfReach=(24-(that.reportArr[i]['Idle Time']+that.reportArr[i]['Stoppage Time']+that.reportArr[i]['Moving Time'])).toFixed(2)
|
||||||
that.clocation_1(that.reportArr[i], function (err, succ) {
|
}else{
|
||||||
if (err) {
|
that.reportArr[i].outOfReach=0.0
|
||||||
console.log(err);
|
}
|
||||||
j++;
|
|
||||||
} else {
|
that.clocation_1(that.reportArr[i], function (err, succ) {
|
||||||
if(!(that.finalArr.includes(succ))){
|
if (err) {
|
||||||
console.log(that.finalArr.includes(succ));
|
console.log(err);
|
||||||
for(var k=0;k<that.finalArr.length;k++){
|
j++;
|
||||||
if(succ.Device_ID!=that.finalArr[k].Device_ID && succ.Date!=that.finalArr[k].Date){
|
} else {
|
||||||
if(!(that.finalArr.includes(succ))){
|
if(!(that.finalArr.includes(succ))){
|
||||||
that.finalArr.push(succ);
|
console.log(that.finalArr.includes(succ));
|
||||||
|
for(var k=0;k<that.finalArr.length;k++){
|
||||||
|
if(succ.Device_ID!=that.finalArr[k].Device_ID && succ.Date!=that.finalArr[k].Date){
|
||||||
|
if(!(that.finalArr.includes(succ))){
|
||||||
|
that.finalArr.push(succ);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
console.log(that.finalArr.includes(succ));
|
||||||
|
}
|
||||||
|
that.finalArr.push(succ);
|
||||||
|
console.log(that.finalArr);
|
||||||
|
j++;
|
||||||
|
if (j === that.reportArr.length) {
|
||||||
|
that.Load = false;
|
||||||
|
var x = [];
|
||||||
|
that.finalArr.sort(function(a,b){
|
||||||
|
// Turn your strings into dates, and then subtract them
|
||||||
|
// to get a value that is either negative, positive, or zero.
|
||||||
|
var aDate:any = new Date(a.Date);
|
||||||
|
var bDate:any = new Date(b.Date);
|
||||||
|
return bDate - aDate;
|
||||||
|
});
|
||||||
|
|
||||||
|
var filtered=_.uniqWith(that.finalArr, _.isEqual);
|
||||||
|
|
||||||
|
console.log(filtered)
|
||||||
|
|
||||||
|
callback({ data: filtered });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
})
|
||||||
console.log(that.finalArr.includes(succ));
|
|
||||||
}
|
|
||||||
that.finalArr.push(succ);
|
|
||||||
console.log(that.finalArr);
|
|
||||||
j++;
|
|
||||||
if (j === that.reportArr.length) {
|
|
||||||
that.Load = false;
|
|
||||||
var x = [];
|
|
||||||
that.finalArr.sort(function(a,b){
|
|
||||||
// Turn your strings into dates, and then subtract them
|
|
||||||
// to get a value that is either negative, positive, or zero.
|
|
||||||
var aDate:any = new Date(a.Date);
|
|
||||||
var bDate:any = new Date(b.Date);
|
|
||||||
return bDate - aDate;
|
|
||||||
});
|
|
||||||
|
|
||||||
var filtered=_.uniqWith(that.finalArr, _.isEqual);
|
|
||||||
|
|
||||||
console.log(filtered)
|
|
||||||
|
|
||||||
callback({ data: filtered });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
|
||||||
console.log("HDH",that.reportArr)
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
that.Load = false;
|
that.Load = false;
|
||||||
callback({ data: [] });
|
callback({ data: [] });
|
||||||
|
|
|
||||||
|
|
@ -325,32 +325,64 @@ export class DisatanceReportComponent implements OnInit {
|
||||||
if (that.reportArr.length != 0) {
|
if (that.reportArr.length != 0) {
|
||||||
var j = 0;
|
var j = 0;
|
||||||
that.finalArr = [];
|
that.finalArr = [];
|
||||||
for (var i = 0; i < that.reportArr.length; i++) {
|
|
||||||
if (that.reportArr[i]){
|
|
||||||
|
|
||||||
that.clocation_1(that.reportArr[i], function (err, succ) {
|
let latLongArray :any[] = [];
|
||||||
if (err) {
|
that.reportArr.forEach((deData)=>{
|
||||||
console.log(err);
|
let latLng = {
|
||||||
j++;
|
lat: deData.start_location ? deData.start_location.lat ? deData.start_location.lat : 0:0,
|
||||||
} else {
|
long: deData.start_location ? deData.start_location.long ? deData.start_location.long : 0:0
|
||||||
console.log(succ);
|
}
|
||||||
that.finalArr.push(succ);
|
latLongArray.push(latLng)
|
||||||
console.log(that.finalArr);
|
let end_latLng = {
|
||||||
j++;
|
lat: deData.end_location ? deData.end_location.lat ? deData.end_location.lat : 0:0,
|
||||||
if (j === that.reportArr.length) {
|
long: deData.end_location ? deData.end_location.long ? deData.end_location.long : 0:0
|
||||||
that.Load = false;
|
}
|
||||||
callback({ data: that.finalArr });
|
latLongArray.push(end_latLng)
|
||||||
}
|
})
|
||||||
|
|
||||||
|
that.contactService.getAddressByApiBulk(latLongArray).subscribe(latLongAddress => {
|
||||||
|
let indexCounter = 0;
|
||||||
|
that.reportArr.forEach((deData,index)=>{
|
||||||
|
let latLng = {
|
||||||
|
lat: deData.start_location ? deData.start_location.lat ? deData.start_location.lat : 0:0,
|
||||||
|
long: deData.start_location ? deData.start_location.long ? deData.start_location.long : 0:0
|
||||||
}
|
}
|
||||||
|
that.contactService.latLongAddress[latLng.long+'_'+latLng.lat] = latLongAddress[indexCounter];
|
||||||
|
indexCounter++;
|
||||||
|
let end_latLng = {
|
||||||
|
lat: deData.end_location ? deData.end_location.lat ? deData.end_location.lat : 0:0,
|
||||||
|
long: deData.end_location ? deData.end_location.long ? deData.end_location.long : 0:0
|
||||||
|
}
|
||||||
|
that.contactService.latLongAddress[end_latLng.long+'_'+end_latLng.lat] = latLongAddress[indexCounter];
|
||||||
|
indexCounter++;
|
||||||
|
if(deData) {
|
||||||
|
|
||||||
|
|
||||||
|
that.clocation_1(deData, function (err, succ) {
|
||||||
|
if (err) {
|
||||||
|
console.log(err);
|
||||||
|
j++;
|
||||||
|
} else {
|
||||||
|
console.log(succ);
|
||||||
|
that.finalArr.push(succ);
|
||||||
|
console.log(that.finalArr);
|
||||||
|
j++;
|
||||||
|
if (j === that.reportArr.length) {
|
||||||
|
that.Load = false;
|
||||||
|
callback({ data: that.finalArr });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
that.Load = false;
|
||||||
|
callback({ data: [] });
|
||||||
|
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}else{
|
|
||||||
that.Load = false;
|
|
||||||
callback({ data: [] });
|
|
||||||
}
|
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
that.Load = false;
|
that.Load = false;
|
||||||
that.firstcall = true;
|
that.firstcall = true;
|
||||||
|
|
|
||||||
|
|
@ -443,35 +443,98 @@ testTable() {
|
||||||
if (that.summary.length != 0) {
|
if (that.summary.length != 0) {
|
||||||
var j = 0;
|
var j = 0;
|
||||||
that.finalArr = [];
|
that.finalArr = [];
|
||||||
for (var i = 0; i < that.summary.length; i++) {
|
|
||||||
|
let latLongArray :any[] = [];
|
||||||
that.clocation_1(that.summary[i], function (err, succ) {
|
that.summary.forEach((deData)=>{
|
||||||
if (err) {
|
let latLng = {lat:0,
|
||||||
console.log(err);
|
long:0};
|
||||||
j++;
|
let end_latLng = {lat:0,
|
||||||
} else {
|
long:0};
|
||||||
that.finalArr.push(succ);
|
if (deData.start_location) {
|
||||||
console.log(that.finalArr);
|
latLng = {
|
||||||
j++;
|
lat: deData.start_location.lat ? deData.start_location.lat : 0,
|
||||||
if (j === that.summary.length) {
|
long: deData.start_location.long ? deData.start_location.long : 0
|
||||||
that.Load = false;
|
|
||||||
var x = [];
|
|
||||||
that.finalArr.sort(function(a,b){
|
|
||||||
// Turn your strings into dates, and then subtract them
|
|
||||||
// to get a value that is either negative, positive, or zero.
|
|
||||||
var aDate:any = new Date(a.Date);
|
|
||||||
var bDate:any = new Date(b.Date);
|
|
||||||
return bDate - aDate;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
callback({ data: that.finalArr });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
if (deData.today_start_location) {
|
||||||
|
latLng = {
|
||||||
|
lat: deData.today_start_location.lat ? deData.today_start_location.lat : 0,
|
||||||
|
long: deData.today_start_location.long ? deData.today_start_location.long : 0
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
deData.today_start_location = deData.start_location;
|
||||||
|
}
|
||||||
|
latLongArray.push(latLng)
|
||||||
|
if (deData.last_location) {
|
||||||
|
end_latLng = {
|
||||||
|
lat: deData.last_location.lat ? deData.last_location.lat : 0,
|
||||||
|
long: deData.last_location.long ? deData.last_location.long : 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (deData.end_location) {
|
||||||
|
end_latLng = {
|
||||||
|
lat: deData.end_location.lat ? deData.end_location.lat : 0,
|
||||||
|
long: deData.end_location.long ? deData.end_location.long : 0
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
deData.end_location = deData.last_location;
|
||||||
|
}
|
||||||
|
latLongArray.push(end_latLng)
|
||||||
|
})
|
||||||
|
|
||||||
}
|
that.contactService.getAddressByApiBulk(latLongArray).subscribe(latLongAddress => {
|
||||||
|
let indexCounter = 0;
|
||||||
|
that.summary.forEach((deData,index)=>{
|
||||||
|
let latLng = {
|
||||||
|
lat: deData.today_start_location ? deData.today_start_location.lat ? deData.today_start_location.lat : 0:0,
|
||||||
|
long: deData.today_start_location ? deData.today_start_location.long ? deData.today_start_location.long : 0:0
|
||||||
|
}
|
||||||
|
that.contactService.latLongAddress[latLng.long+'_'+latLng.lat] = latLongAddress[indexCounter];
|
||||||
|
indexCounter++;
|
||||||
|
let end_latLng = {
|
||||||
|
lat: deData.end_location ? deData.end_location.lat ? deData.end_location.lat : 0:0,
|
||||||
|
long: deData.end_location ? deData.end_location.long ? deData.end_location.long : 0:0
|
||||||
|
}
|
||||||
|
that.contactService.latLongAddress[end_latLng.long+'_'+end_latLng.lat] = latLongAddress[indexCounter];
|
||||||
|
indexCounter++;
|
||||||
|
if(deData) {
|
||||||
|
|
||||||
|
//location code
|
||||||
|
that.clocation_1(deData, function (err, succ) {
|
||||||
|
if (err) {
|
||||||
|
console.log(err);
|
||||||
|
j++;
|
||||||
|
} else {
|
||||||
|
that.finalArr.push(succ);
|
||||||
|
console.log(that.finalArr);
|
||||||
|
j++;
|
||||||
|
if (j === that.summary.length) {
|
||||||
|
that.Load = false;
|
||||||
|
var x = [];
|
||||||
|
that.finalArr.sort(function(a,b){
|
||||||
|
// Turn your strings into dates, and then subtract them
|
||||||
|
// to get a value that is either negative, positive, or zero.
|
||||||
|
var aDate:any = new Date(a.Date);
|
||||||
|
var bDate:any = new Date(b.Date);
|
||||||
|
return bDate - aDate;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
callback({ data: that.finalArr });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
} else {
|
||||||
|
that.Load = false;
|
||||||
|
callback({ data: [] });
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
that.Load = false;
|
that.Load = false;
|
||||||
callback({ data: [] });
|
callback({ data: [] });
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue