我爲我的應用程序添加了一個mapKit,並且我將地圖的中間位置設置爲lat和lng中的當前位置。我能夠得到它的工作,但是,它經常更新。我只希望它在應用程序加載時更新一次,然後不再更新。也許每2分鐘更新一次。這裏是我的代碼:只更新位置一次
func locationManager(manager: CLLocationManager!,
didUpdateLocations locations: [AnyObject]!)
{
var latestLocation = locations.last as! CLLocation
let location = CLLocationCoordinate2D(latitude: latestLocation.coordinate.latitude, longitude: latestLocation.coordinate.longitude)
let span = MKCoordinateSpanMake(0.015, 0.015)
//Let our point be the center of our span
//region holds value of span and location
let region = MKCoordinateRegion(center: location, span: span)
//set up region on mapView
mapView.setRegion(region, animated: true)
//MKPointAnnotation defines a concrete annotation
let annotation = MKPointAnnotation()
}