From 8f326880384508f1f627a66dbfe65f284575a51a Mon Sep 17 00:00:00 2001
From: Adarsh K <adarsh@techware.in>
Date: Mon, 9 Mar 2020 19:17:43 +0530
Subject: [PATCH] changes

---
 src/app/nearby/nearby.page.ts  |  2 ++
 src/config/address.service.ts  | 26 +++++++++++++++++++++++---
 src/config/services/address.ts |  1 +
 3 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/src/app/nearby/nearby.page.ts b/src/app/nearby/nearby.page.ts
index 31b4a6b..bf1d015 100644
--- a/src/app/nearby/nearby.page.ts
+++ b/src/app/nearby/nearby.page.ts
@@ -120,12 +120,14 @@ export class NearbyPage implements OnInit {
   mapReady(map) {
     map.addListener('dragend', () => {
       console.log(this.newCenterLat, this.newCenterLng);
+      this.getAddress(this.newCenterLat, this.newCenterLng);
     });
   }
   centerChange(e) {
     console.log(e);
     this.newCenterLat = e.lat;
     this.newCenterLng = e.lng;
+    this.getAddress(this.newCenterLat, this.newCenterLng);
   }
 
   goToPage(path, data = null) {
diff --git a/src/config/address.service.ts b/src/config/address.service.ts
index 4d2d42c..7837cd9 100644
--- a/src/config/address.service.ts
+++ b/src/config/address.service.ts
@@ -42,7 +42,8 @@ export class AddressService {
             defaultVal: item.defaultVal,
             building: item.building,
             landmark: item.landmark,
-            addressId: item.addressId
+            addressId: item.addressId,
+            nearest: false
           };
           this.addressList.push(address);
         });
@@ -72,7 +73,8 @@ export class AddressService {
           defaultVal: item.defaultVal,
           building: item.building,
           landmark: item.landmark,
-          addressId: item.addressId
+          addressId: item.addressId,
+          nearest: false
         };
         this.defaultAdd = address;
         console.log(this.defaultAdd);
@@ -203,7 +205,8 @@ export class AddressService {
                   defaultVal: item.defaultVal,
                   building: item.building,
                   landmark: item.landmark,
-                  addressId: item.addressId
+                  addressId: item.addressId,
+                  nearest: true
                 };
                 this.nearestList.push(address);
               });
@@ -212,6 +215,23 @@ export class AddressService {
             } else {
               // alert('No Orders Found');
             }
+
+            if (this.addressList.length > 0 && this.nearestList.length > 0) {
+              this.addressList.forEach((address) => {
+                const index = this.nearestList.findIndex(x => x.addressId === address.addressId);
+                if (index >= 0) {
+                  address.nearest = true;
+                }
+              });
+            }
+            console.log(this.addressList);
+
+            this.addressList = this.addressList.sort((a: any, b: any) => {
+              return b.nearest - a.nearest;
+            });
+
+            console.log(this.addressList);
+
           });
         } else {
           console.log('No such document!');
diff --git a/src/config/services/address.ts b/src/config/services/address.ts
index 988ab43..71a760f 100644
--- a/src/config/services/address.ts
+++ b/src/config/services/address.ts
@@ -22,4 +22,5 @@ export interface AddressList {
     building: string;
     latLng: any;
     landmark: string;
+    nearest: boolean;
 }
--
libgit2 0.27.1