-
-
Notifications
You must be signed in to change notification settings - Fork 120
Description
On Android, using GoogleMaps.CameraUpdate.fromCameraPosition() to update the map's camera, especially when including bearing, results in a java.lang.NullPointerException from the native Google Maps SDK.
Steps to Reproduce
-
Set up a blank nativescript-vue project
-
Initialize a nativescript/google-maps MapView.
-
Attempt to create a CameraUpdate using GoogleMaps.CameraUpdate.fromCameraPosition() with a valid CameraPosition object.
import * as GoogleMaps from '@nativescript/google-maps';
// Assume 'map' is an initialized GoogleMaps.GoogleMap instance
// Assume 'map.cameraPosition' has valid data.
// Assume 'newHeading' is a valid number (e.g., from device orientation).
const newCameraPosition: GoogleMaps.CameraPosition = {
target: map.cameraPosition.target,
zoom: map.cameraPosition.zoom,
tilt: map.cameraPosition.tilt,
bearing: newHeading, // Or any valid number, e.g., 20
};
console.log('Input newCameraPosition:', JSON.stringify(newCameraPosition)); // This logs a valid object
try {
const cameraUpdate = GoogleMaps.CameraUpdate.fromCameraPosition(newCameraPosition);
// This line below is never reached
console.log('CameraUpdate created successfully.');
} catch (e: any) {
console.error("Error creating CameraUpdate:", e);
if (global.isAndroid && e.nativeException) {
console.error("Native Android Exception:", e.nativeException);
}
}
Observed Error :
Error creating CameraUpdate fromCameraPosition: Error: java.lang.NullPointerException: cameraPosition must not be null
Native Android Exception during CameraUpdate creation: java.lang.NullPointerException: cameraPosition must not be null
Context & Impact :
-
The newCameraPosition JavaScript object supplied to fromCameraPosition is confirmed to be valid (no null, undefined, or NaN values).
-
This specific NullPointerException indicates an issue in the plugin's native bridge when converting the JavaScript CameraPosition object for fromCameraPosition.
-
As per the plugin's CameraUpdate API, fromCameraPosition is the only method that allows for setting the bearing alongside other camera parameters.
-
This bug currently prevents any programmatic control over the map's bearing, which is critical for features like compass-oriented maps.
Environment
- nativescript-vue: "3.0.1"
- @nativescript/google-maps : "1.8.0"
- Platform: Android
- Device Model: emulated Pixel 4 but also on hardware