I have an issue. My current location is displayed and centered in a map view however the map region doesn\'t get zoomed in to. I tried taking Rob\'s advice by taking span an
Swift 3:
import GoogleMaps
import GooglePlaces
import CoreLocation
import UIKit
class LocationMapView: UIViewController, GMSMapViewDelegate, CLLocationManagerDelegate {
@IBOutlet weak var mapView: GMSMapView!
var mapViewZoomStepperValue: Float = 0.0
@IBOutlet weak var mapViewZoomStepper: UIStepper!
override func viewDidLoad() {
super.viewDidLoad()
mapViewZoomStepper.minimumValue = -100
}
@IBAction func mapViewZoomStepperValueChanged(_ sender: Any) {
if (Float(mapViewZoomStepper.value) > mapViewZoomStepperValue){
mapViewZoomStepperValue = Float(mapViewZoomStepper.value)
zoomIn()
}else{
mapViewZoomStepperValue = Float(mapViewZoomStepper.value)
zoomOut()
}
}
func zoomIn() {
print("Zoom in!!")
if mapView.camera.zoom == mapView.maxZoom {
return
}
let currentZoom = mapView.camera.zoom + 1
mapViewZoomController(currentZoom)
}
func zoomOut() {
print("Zoom out!!")
if mapView.camera.zoom == mapView.minZoom {
return
}
let currentZoom = mapView.camera.zoom - 1
mapViewZoomController(currentZoom)
}
func mapViewZoomController(_ level: Float) {
let point: CGPoint = mapView.center
let coor: CLLocationCoordinate2D = mapView.projection.coordinate(for: point)
let camera = GMSCameraPosition.camera(withLatitude: coor.latitude, longitude: coor.longitude, zoom: Float(level))
mapView.animate(to: camera)
}
}