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,9 +1649,20 @@ 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)
|
return this.http.post(this.dev_url +'/googleAddress/getGoogleAddress',latlng)
|
||||||
.map(res => res.json());
|
.map(res => res.json());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
getAddressByApiBulk(latlng){
|
||||||
|
|
||||||
|
return this.http.post(this.dev_url +'/googleAddress/getGoogleAddressBulk',latlng)
|
||||||
|
.map(res => res.json());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -580,9 +580,24 @@ 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++) {
|
|
||||||
|
|
||||||
that.clocation_1(that.reportArr[i], function (err, succ) {
|
let latLongArray :any[] = [];
|
||||||
|
that.reportArr.forEach((deData)=>{
|
||||||
|
let latLng = {
|
||||||
|
lat: deData.startLat ? deData.startLat : 0,
|
||||||
|
long: deData.startLng ? deData.startLng : 0
|
||||||
|
}
|
||||||
|
latLongArray.push(latLng)
|
||||||
|
})
|
||||||
|
|
||||||
|
that.contactService.getAddressByApiBulk(latLongArray).subscribe(latLongAddress => {
|
||||||
|
that.reportArr.forEach((deData,index)=>{
|
||||||
|
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) {
|
if (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
j++;
|
j++;
|
||||||
|
|
@ -596,9 +611,12 @@ testTable() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
that.Load = false;
|
that.Load = false;
|
||||||
that.firstcall=true;
|
that.firstcall=true;
|
||||||
|
|
@ -793,13 +811,6 @@ tab:any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 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") {
|
||||||
var adata = {
|
var adata = {
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -325,9 +325,39 @@ 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]) {
|
|
||||||
|
|
||||||
|
let latLongArray :any[] = [];
|
||||||
|
that.reportArr.forEach((deData)=>{
|
||||||
|
|
||||||
|
let latLng = {
|
||||||
|
lat: "0",
|
||||||
|
long: "0"
|
||||||
|
};
|
||||||
|
|
||||||
|
latLng = {
|
||||||
|
long: deData.last_loc && deData.last_loc.coordinates && deData.last_loc.coordinates.length && deData.last_loc.coordinates[0] ? deData.last_loc.coordinates[0] : 0,
|
||||||
|
lat: deData.last_loc && deData.last_loc.coordinates && deData.last_loc.coordinates.length && deData.last_loc.coordinates[1] ? deData.last_loc.coordinates[1]: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
if (that.reportArr[i].status_updated_at == undefined) {
|
||||||
let dev_status_1 = that.reportArr[i].status ? that.reportArr[i].status : "Not available";
|
let dev_status_1 = that.reportArr[i].status ? that.reportArr[i].status : "Not available";
|
||||||
that.reportArr[i].status = dev_status_1;
|
that.reportArr[i].status = dev_status_1;
|
||||||
|
|
@ -401,6 +431,9 @@ export class CurrentPositionReportComponent implements OnInit {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
that.Load = false;
|
that.Load = false;
|
||||||
that.firstcall = true;
|
that.firstcall = true;
|
||||||
|
|
|
||||||
|
|
@ -210,31 +210,45 @@ 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 = [];
|
||||||
|
|
||||||
|
let latLongArray :any[] = [];
|
||||||
|
that.reportArr.forEach((deData)=>{
|
||||||
|
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
|
||||||
|
}
|
||||||
|
latLongArray.push(latLng)
|
||||||
|
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
|
||||||
|
}
|
||||||
|
latLongArray.push(end_latLng)
|
||||||
|
})
|
||||||
|
|
||||||
|
that.contactService.getAddressByApiBulk(latLongArray).subscribe(latLongAddress => {
|
||||||
|
let indexCounter = 0;
|
||||||
for (var i = 0; i < that.reportArr.length; i++) {
|
for (var i = 0; i < that.reportArr.length; i++) {
|
||||||
|
let latLng = {
|
||||||
// if(that.reportArr[i].distanceVariation){
|
lat: that.reportArr[i].start_location ? that.reportArr[i].start_location.lat ? that.reportArr[i].start_location.lat : 0:0,
|
||||||
// console.log("IN");
|
long: that.reportArr[i].start_location ? that.reportArr[i].start_location.long ? that.reportArr[i].start_location.long : 0:0
|
||||||
|
}
|
||||||
// if(that.reportArr[i].distanceVariation[0]=="+"){
|
that.contactService.latLongAddress[latLng.long+'_'+latLng.lat] = latLongAddress[indexCounter];
|
||||||
// that.reportArr[i]['Distance(Kms)']=that.reportArr[i]['Distance(Kms)']+(that.reportArr[i]['Distance(Kms)']/100)*Number(that.reportArr[i].distanceVariation.substring(1))
|
indexCounter++;
|
||||||
// console.log("IN",(that.reportArr[i]['Distance(Kms)']/100)*Number(that.reportArr[i].distanceVariation.substring(1)));
|
let end_latLng = {
|
||||||
// }else{
|
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.reportArr[i]['Distance(Kms)']=that.reportArr[i]['Distance(Kms)']-(that.reportArr[i]['Distance(Kms)']/100)*Number(that.reportArr[i].distanceVariation.substring(1))
|
}
|
||||||
// console.log("IN-",that.reportArr[i]['Distance(Kms)']);
|
that.contactService.latLongAddress[end_latLng.long+'_'+end_latLng.lat] = latLongAddress[indexCounter];
|
||||||
// }
|
console.log('indexCounter++',indexCounter,i)
|
||||||
// }
|
indexCounter++;
|
||||||
|
|
||||||
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){
|
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.reportArr[i].outOfReach=(24-(that.reportArr[i]['Idle Time']+that.reportArr[i]['Stoppage Time']+that.reportArr[i]['Moving Time'])).toFixed(2)
|
||||||
}else{
|
}else{
|
||||||
that.reportArr[i].outOfReach=0.0
|
that.reportArr[i].outOfReach=0.0
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
that.clocation_1(that.reportArr[i], function (err, succ) {
|
that.clocation_1(that.reportArr[i], function (err, succ) {
|
||||||
|
|
@ -277,7 +291,12 @@ export class DayWiseReportComponent implements OnInit {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
console.log("HDH",that.reportArr)
|
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
that.Load = false;
|
that.Load = false;
|
||||||
callback({ data: [] });
|
callback({ data: [] });
|
||||||
|
|
|
||||||
|
|
@ -325,10 +325,40 @@ 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[] = [];
|
||||||
|
that.reportArr.forEach((deData)=>{
|
||||||
|
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
|
||||||
|
}
|
||||||
|
latLongArray.push(latLng)
|
||||||
|
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
|
||||||
|
}
|
||||||
|
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) {
|
if (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
j++;
|
j++;
|
||||||
|
|
@ -343,14 +373,16 @@ export class DisatanceReportComponent implements OnInit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}else{
|
} else {
|
||||||
that.Load = false;
|
that.Load = false;
|
||||||
callback({ data: [] });
|
callback({ data: [] });
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
that.Load = false;
|
that.Load = false;
|
||||||
that.firstcall = true;
|
that.firstcall = true;
|
||||||
|
|
|
||||||
|
|
@ -443,9 +443,64 @@ 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++) {
|
|
||||||
|
|
||||||
that.clocation_1(that.summary[i], function (err, succ) {
|
let latLongArray :any[] = [];
|
||||||
|
that.summary.forEach((deData)=>{
|
||||||
|
let latLng = {lat:0,
|
||||||
|
long:0};
|
||||||
|
let end_latLng = {lat:0,
|
||||||
|
long:0};
|
||||||
|
if (deData.start_location) {
|
||||||
|
latLng = {
|
||||||
|
lat: deData.start_location.lat ? deData.start_location.lat : 0,
|
||||||
|
long: deData.start_location.long ? deData.start_location.long : 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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) {
|
if (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
j++;
|
j++;
|
||||||
|
|
@ -470,8 +525,16 @@ testTable() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
} 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