Map button refresh location

前端 未结 3 2055
清酒与你
清酒与你 2021-01-02 23:06

I am working on my first swift application for the iPad. Thus far I have a basic mapview with a button in the bottom toolbar, which I would like to refresh and focus onto th

3条回答
  •  独厮守ぢ
    2021-01-03 00:07

    You can update your location with this function:

    func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
        let location = locations.last as CLLocation
    
        let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)        
        let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))
    
        self.map.setRegion(region, animated: true)
    }
    

    If your target is iOS 8, you need to add the NSLocationAlwaysUsageDescription key in your Info.plist.

提交回复
热议问题