nativescript-google-maps-sdk icon indicating copy to clipboard operation
nativescript-google-maps-sdk copied to clipboard

How to moveCamera position

Open meshmmanuel opened this issue 7 years ago • 3 comments

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.

meshmmanuel avatar Jun 25 '18 13:06 meshmmanuel

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.

saibbyweb avatar Jan 18 '19 10:01 saibbyweb

com.google.android.gms does not recognize it.

Does anyone have a solution?

Thank you!

vallemar avatar May 10 '20 21:05 vallemar

I answer myself.

Add declare var com: any; and works! ->

import {Marker, Position} from "nativescript-google-maps-sdk"; declare var com:any;

vallemar avatar May 10 '20 21:05 vallemar