cordova-plugin-googlemaps icon indicating copy to clipboard operation
cordova-plugin-googlemaps copied to clipboard

map.animateCamera and marker.setPosition don't work when app is in background

Open globalsysdesenv opened this issue 9 years ago • 21 comments

I'm submitting a ... (check one with "x") [ ] question [X ] any problem or bug report [ ] feature request

The plugin version: (check one with "x") [ ] 2.0-beta3 (github) [X] 2.0 (npm)

If you choose 'problem or bug report', please select OS: (check one with "x") [X] Android [ ] iOS

cordova information: (run $> cordova plugin list)

com.googlemaps.ios 2.3.0 "Google Maps SDK for iOS"
cordova-background-geolocation 2.8.5 "BackgroundGeolocation"
cordova-plugin-app-version 0.1.9 "AppVersion"
cordova-plugin-background-fetch 5.1.1 "CDVBackgroundFetch"
cordova-plugin-cocoalumberjack 0.0.4 "CocoaLumberjack"
cordova-plugin-cocoapod-support 1.3.0 "Cordova CocoaPods Dependency Support"
cordova-plugin-compat 1.2.0 "Compat"
cordova-plugin-console 1.0.7 "Console"
cordova-plugin-crosswalk-webview 2.3.0 "Crosswalk WebView Engine"
cordova-plugin-device 1.1.6 "Device"
cordova-plugin-geolocation 2.4.3 "Geolocation"
cordova-plugin-googlemaps 2.0.11 "cordova-plugin-googlemaps"
cordova-plugin-network-information 1.3.3 "Network Information"
cordova-plugin-splashscreen 4.0.3 "Splashscreen"
cordova-plugin-statusbar 2.2.3 "StatusBar"
cordova-plugin-whitelist 1.3.2 "Whitelist"
cordova.plugins.diagnostic.api-22 2.3.10-api-22 "Diagnostic"
ionic-plugin-keyboard 1.0.9 "Keyboard"
onesignal-cordova-plugin 2.1.2 "OneSignal Push Notifications"

If you use @ionic-native/google-maps, please show me the package.json

Current behavior:

I movement app in background for few minutes and back to the app. When I back, the map center is the same that was and it starts to set position for that moment.

Expected behavior:

When I back to the app, the map center has to be real location, because it changed the position when the app was in background.

If I only back to the 1.4.5 version, the app works correctly.

Steps to reproduce:

Screen capture or video record:

Related code, data or error log (please format your code or data):

motoristaController.js line 418

This method is called by locationService.js

$rootScope.setMapCenter = function () {
        var point = new google.maps.LatLng(usuario.Latitude, usuario.Longitude);
        var spherical = google.maps.geometry.spherical;
        var pontoFuturo;

        if ($rootScope.isMoving && $rootScope.bearing) {
            pontoFuturo = spherical.computeOffset(point, 10, $rootScope.bearing);
        }
        else {
            pontoFuturo = point;
        }

        var animateOpt = {
            target: { "lat": pontoFuturo.lat(), "lng": pontoFuturo.lng() },
            duration: 500,
            tilt: 60,
            zoom: 19
        };

        if ($rootScope.bearing) {
            animateOpt.bearing = $rootScope.bearing;
        }

        if ($scope.map) {
            $scope.map.animateCamera(animateOpt);
        }
    }

globalsysdesenv avatar Oct 09 '17 18:10 globalsysdesenv

There is no function to track your position in background in this plugin.

By the way, this plugin also has the spherical.computeOffset. https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v2.0.0/class/utilities/geometry/spherical/README.md

wf9a5m75 avatar Oct 09 '17 19:10 wf9a5m75

Are you sure? Why v.1.4.5 this process works fine?

globalsysdesenv avatar Oct 09 '17 20:10 globalsysdesenv

The v2.0 is not related with v1.4.5 at all.

wf9a5m75 avatar Oct 09 '17 20:10 wf9a5m75

If you want to check your app, please share your project files (all files) on github (or others). I will check it. Otherwise I don't do anything, because the plugin does not have such a feature.

wf9a5m75 avatar Oct 09 '17 20:10 wf9a5m75

Ok, you can see in https://github.com/globalsysdesenv/testenovomapa

globalsysdesenv avatar Oct 09 '17 20:10 globalsysdesenv

Thank you, I will check it later.

wf9a5m75 avatar Oct 09 '17 20:10 wf9a5m75

Thank you for waiting. I was busy today (always busy though). I finally built your app.

In your code, this code is deprecated. The launchNavigator will be removed in the next release.

        plugin.google.maps.external.launchNavigation({
            "from": origem.latitude + "," + origem.longitude,
            "to": destino
        });

Please use this plugin https://github.com/dpa99c/phonegap-launch-navigator

wf9a5m75 avatar Oct 10 '17 01:10 wf9a5m75

Ok, thank you!

What about the background set position, did you find something?

globalsysdesenv avatar Oct 10 '17 01:10 globalsysdesenv

No. I used your app during my commute, from my company to my home, and your app reproduced the route after I reached to my house.

wf9a5m75 avatar Oct 10 '17 02:10 wf9a5m75

Please try drive with app opened, then leave app in background for a few minutes, then open the app. The map center will set delayed.

globalsysdesenv avatar Oct 11 '17 18:10 globalsysdesenv

I'm sorry, but I'm so busy. I can not spend for your app debugging. I only support for the plugin problems.

wf9a5m75 avatar Oct 11 '17 18:10 wf9a5m75

I'm sorry. But your plugin stop to work in my app when I migrate a version. It doesn't set marker positions or map center in background, this is the problem. Not my app.

I'll try another way.

globalsysdesenv avatar Oct 11 '17 18:10 globalsysdesenv

Please create a test project (not tracking real GPS location, but provide sample locations then read from it). I will check it. Until you provide it, I don't do any thing.

If the map.animateCamera() has problems, I should receive more claims. But so far, only from you. So I think the problem is in your code.

wf9a5m75 avatar Oct 11 '17 18:10 wf9a5m75

Hello,

I updated the project without background geolocation. Now I have a locations array and an interval setting positions each 5 seconds. The behaviour is the same.

https://github.com/globalsysdesenv/testenovomapa/

  • To reproduce, you have to: Open the app and wait marker starts, seconds later leave app in background and wait a few seconds, then open the app. The marker position and map center will be set delayed.

  • We recorded a video with the behaviour. You can see in https://drive.google.com/open?id=0B5H_mQN9oZq6QmlnVGowMTkxZms

globalsysdesenv avatar Oct 14 '17 16:10 globalsysdesenv

Hello, could you help us?

globalsysdesenv avatar Oct 18 '17 12:10 globalsysdesenv

I'm so busy. I have been processing one by one. Please wait.

wf9a5m75 avatar Oct 18 '17 13:10 wf9a5m75

Thank you for waiting. Since your project is kind of complex, I create a simple example project.

https://github.com/mapsplugin/animateCameraTest

  onMapReady: function() {
    var self = this;
    this.map.addMarker({
       position: {lat: -20.355389, lng : -40.296152 }
    }, function(marker) {

      //----------------------------------------------
      // For debugging, create circles on the points
      //----------------------------------------------
      var mvcArray = new plugin.google.maps.BaseArrayClass(self.locations);
      mvcArray.forEach(function(location, cb) {
        self.map.addCircle({
          center: {
            lat: location.coords.latitude,
            lng: location.coords.longitude
          },
          radius: 3,
          color: "red"
        }, cb);
      }, function() {

        //----------------------------------------------
        // start animation
        //----------------------------------------------
        var timer = setInterval(function() {
          var location = self.locations.shift();
          if (!location) {
            clearInterval(timer);
            return;
          }
          var currentPos = marker.getPosition();
          var nextPos = {
            lat: location.coords.latitude,
            lng: location.coords.longitude
          };

          var fraction = 0;
          var steps = 30;
          var fractionStep = 1 / steps;
          var animateTimer = setInterval(function() {
            fraction += fractionStep;
            marker.setPosition(plugin.google.maps.geometry.spherical.interpolate(currentPos, nextPos, fraction));
            if (fraction >= 1.0) {
              clearInterval(animateTimer);
              animateTimer = null;
            }
          }, 2000 / steps);


          self.map.animateCamera({
            target: {
              lat: location.coords.latitude,
              lng: location.coords.longitude
            },
            duration: 500,
            tilt: 60,
            zoom: 19
          });
        }, 2000);
      });
    });
  }

First test, I recorded the app always in front. https://youtu.be/CXEBBYCulU0

After that, I recored the app that goes to front and back sometimes. https://youtu.be/e1CGw-a0kFk

Well, it seems the code keep the same speed.

wf9a5m75 avatar Oct 19 '17 20:10 wf9a5m75

On 14 seconds, the positions are changed in the map just after you go to the front, not set in background. This is the problem.

The behaviour is the same from my code.

globalsysdesenv avatar Oct 25 '17 12:10 globalsysdesenv

During the background, it seems Android OS (especially version 5 and over) stops the UI code in order to save the battery usage. So program is stopped except service. So it is impossible to keep the map, and not good for user.

If you don't agree this, you should not use this plugin. Because there is no solution, and it is not plugin bug.

wf9a5m75 avatar Oct 25 '17 14:10 wf9a5m75

OK, but we don't understand why 1.4.5 version works. The behaviour is not the same.

With this way we will have to fork the 1.4.5 version and delevop...

globalsysdesenv avatar Oct 25 '17 20:10 globalsysdesenv