ionic-team / ionic-native-google-maps

Google maps plugin for Ionic Native
Other
221 stars 125 forks source link

InvalidValueError while setting Camera Target #92

Closed TdoubleG closed 5 years ago

TdoubleG commented 5 years ago

I'm submitting a ... (check one with "x")

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

cordova information: (run $> cordova plugin list)

cordova-plugin-device 2.0.2 "Device"
cordova-plugin-geolocation 4.0.1 "Geolocation"
cordova-plugin-googlemaps 2.4.2 "cordova-plugin-googlemaps"
cordova-plugin-ionic-keyboard 2.1.2 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 2.1.3 "cordova-plugin-ionic-webview"
cordova-plugin-mauron85-background-geolocation 2.3.6 "CDVBackgroundGeolocation"
cordova-plugin-splashscreen 5.0.2 "Splashscreen"
cordova-plugin-statusbar 2.4.2 "StatusBar"
cordova-plugin-whitelist 1.3.3 "Whitelist"

 "@ionic-native/core": "^4.15.0",
"@ionic-native/google-maps": "^4.14.0",

Current behavior:

I want to set the map center via this.map.setCameraTarget() but I get this error:

InvalidValueError: setCenter: not a LatLng or LatLngLiteral: not an Object

My LatLng looks like this:

var GOOGLE = {
        lat: 37.422858,
        lng: -122.085065
      };

this.map.setCameraTarget(GOOGLE);

I also tried with ionic-native LatLng but same issue.

I don't know why i get this kind of error

wf9a5m75 commented 5 years ago

Please share your project files on GitHub.

TdoubleG commented 5 years ago

I removed the plugin and platform and reinstalled everything again. The error is gone but it the camera target doesn't change.

Here is what I'm doing:

followUser(position: Geoposition) {
    const userPos: LatLng = new LatLng(position.coords.latitude, position.coords.longitude);
    this.map.animateCamera({
      target: userPos,
      bearing: 0,
      zoom: this.map.getCameraZoom(),
      duration: 500
    }).then( () => {
      this.map.setCameraTarget(userPos);
      console.log(userPos);
    });
  }

The console.log is correct but when I change the user location, the camera doesn't update

wf9a5m75 commented 5 years ago

As I said,

Please share your project files on GitHub.

TdoubleG commented 5 years ago

Found the issue. Was inside my code where I reload the map every time I got a new location. Sorry for the inconvenience.