MapKit zoom to user current location

后端 未结 8 517
慢半拍i
慢半拍i 2021-02-01 17:59

I am trying to simply show user\'s location on the map, but I need to when app launches, the map should zoom to current location ,but I don\'t know why map doesn\'t zoom at all

8条回答
  •  粉色の甜心
    2021-02-01 18:27

    func animateToUserLocation() {
        if let annoation = mapView.annotations.filter ({ $0 is MKUserLocation }).first {
            let coordinate = annoation.coordinate
            let viewRegion = MKCoordinateRegion(center: coordinate, latitudinalMeters: 200, longitudinalMeters: 200)
            mapView.setRegion(viewRegion, animated: true)
        }
    }
    

提交回复
热议问题