Promise.all().then not called in background

Hello all,

I have currently a confusing problem.

I’m using the Google Maps Plugin to rotate a Polygon. This is what my code looks like:

 private rotatePolygon(polygon: Polygon, latLngArray: ILatLng[], angle: number) {
    const pointsPromise = [];

    latLngArray.forEach((latLng: ILatLng) => {
      const point = this.map.fromLatLngToPoint(latLng);
      pointsPromise.push(point);
    });

    const coordsPromise = [];
    Promise.all(pointsPromise).then((results: any[]) => {
      this.map.fromLatLngToPoint(latLngArray[0]).then((originResult: any[]) => {
        const originPoint = {x: originResult[0], y: originResult[1]};
        results.forEach((points: number[]) => {
          const point = {x: points[0], y: points[1]};
          const rotatePoints = this.rotatePoint(point, originPoint, angle);
          const rotatedLatLng = this.map.fromPointToLatLng([rotatePoints.x, rotatePoints.y]);
          coordsPromise.push(rotatedLatLng);
        });

        Promise.all(coordsPromise).then((result: ILatLng[]) => {
          console.log("result:", result);
          polygon.setPoints(result);
        });
      });
    });
  }

When the App is active, the rotation works well. But as soon as the App is in the background the Promise.all Callback is not called anymore. This happens only on Android.

Do you guys know, what I could do?

First of all, you should ask yourself, why this Promise should be executed in the background and if it’s neccessary.

But you can add a listener to your device to check your current app state, take a look here:

Maybe you should put your function (/ execution) into it.

Hope it helps.

Cheers Unkn0wn0x

The developer of the google maps plugin replied already, that it’s necessary to run the fromLatLngToPoint in the UI Thread of Android. So it won’t work in background.