nativescript-google-maps-sdk
nativescript-google-maps-sdk copied to clipboard
How to moveCamera position
onTapLocateUserOnMap($event){
alert("Locating user...");
let camera = new Camera();
camera.latitude = 6.5948;
camera.longitude = 3.3575;
this.mapView.updateCamera();
}
Ths is what I am currenty using but its not working I'm getting this error
ERROR TypeError: nativescript_google_maps_sdk_1.Camera is not a constructor
JS: ERROR CONTEXT {
Please help me.
If you want to move camera to a bounded position, you can use something like this.
/* demo coordinates */
origin.latitude = 0;
origin.longitude = 0;
destination.latitude = 1;
destination.longitude = 1;
/* for android */
let builder = new com.google.android.gms.maps.model.LatLngBounds.Builder();
let position1 = new com.google.android.gms.maps.model.LatLng(origin.latitude,origin.longitude);
let position2 = new com.google.android.gms.maps.model.LatLng(destination.latitude,destination.longitude);
builder.include(position1);
builder.include(position2);
let bounds = builder.build();
let padding = 100;
let cameraUpdate = com.google.android.gms.maps.CameraUpdateFactory.newLatLngBounds(bounds, padding);
this.mapView.gMap.animateCamera(cameraUpdate);
/* for iOS */
let bounds = GMSCoordinateBounds.alloc().init();
let position1 = CLLocationCoordinate2DMake(origin.latitude,origin.longitude);
let position2 = CLLocationCoordinate2DMake(destination.latitude,destination.longitude);
bounds = bounds.includingCoordinate(position1);
bounds = bounds.includingCoordinate(position2);
let update = GMSCameraUpdate.fitBoundsWithPadding(bounds, 100);
this.mapView.gMap.animateWithCameraUpdate(update);
If you only want to move camera to specific position, just don't add position2 to bounds and you're good to go.
com.google.android.gms does not recognize it.
Does anyone have a solution?
Thank you!
I answer myself.
Add declare var com: any; and works! ->
import {Marker, Position} from "nativescript-google-maps-sdk"; declare var com:any;