简体   繁体   中英

How to zoom in/out GoogleMap using button

I am trying to Zoom In and Zoom Out a map by using two button on map. i am follow this way but not get proper solution-

My code is -

var currentZoom:Float = 10

.

func zoomInOut(level:Float)  {
    let camera = GMSCameraPosition.cameraWithLatitude(26.6139, longitude: 77.2090, zoom: level)

    self.customMapView.camera = camera
}

@IBAction func zoomPlus(sender: AnyObject) {

    currentZoom = currentZoom + 1;
    print("Plus")

    self.customMapView.animateToZoom(currentZoom)
}


@IBAction func zoomMinus(sender: AnyObject) {

    currentZoom = currentZoom - 1;
    print("Minus")

    self.customMapView.animateToZoom(currentZoom)
}

Use zoomTo float type parameter in your method and increase/decrease it with Your button action and call as you required.

func ZoomMap(zoomTo: Float){
        let camera = GMSCameraPosition.cameraWithLatitude(26.6139,longitude:77.2090, zoom:zoomTo)
        let mapView = GMSMapView.mapWithFrame(CGRectMake(0, 0, 375, 667), camera:camera)
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM