dapriett / nativescript-google-maps-sdk

Cross Platform Google Maps SDK for Nativescript
MIT License
244 stars 164 forks source link

No Option to center a map after adding marker #366

Open adilsaeed31 opened 5 years ago

adilsaeed31 commented 5 years ago

Hi,

I want to center a map view after adding the marker but there is no easy way to center a map view. Please advise how I can do this.

Thank you.

Regards, Muhammad Adil

dlcole commented 5 years ago

This function would be very useful to me, too.

tylerablake commented 4 years ago

Hi @adilsaeed31 and @dlcole,

I would try storing a reference to the mapView.

If you are using angular, inside of the onMapReady() function you can set the mapView to a property in your component.

    onMapReady = (event) => {
        const mapView: MapView = event.object;
        this.mapView = mapView;
    }

Now that you have a reference to the map, you can update it anywhere you'd like inside of that component, like this.mapView.latitude = 38.1203202

Hope this helps!

TwistedTamarin commented 4 years ago

Using angular:

<MapView [latitude]="your_latitude_property" [longitude]="your_longitude_property"

Whenever you update your properties inside your component. It will jump on it, during change detection.

Also as @tylerablake said. one must store a reference to the map. so you can manipulate it later on.

ps: don't forget that you have to update your properties inside the "zone". otherwise change detection won't happen.

Cheers.