Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/122.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 只更新一次位置_Ios_Iphone_Swift_Mapkit - Fatal编程技术网

Ios 只更新一次位置

Ios 只更新一次位置,ios,iphone,swift,mapkit,Ios,Iphone,Swift,Mapkit,我正在为我的应用程序添加一个地图工具包,我将地图的中间部分设置为人员当前位置,以lat和lng为单位。我可以让它工作,但是,它不断更新,每这么频繁。我只希望它在应用程序加载时更新一次,然后不再更新。可能每2分钟更新一次。这是我的密码: func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) { var latestLocation = locatio

我正在为我的应用程序添加一个地图工具包,我将地图的中间部分设置为人员当前位置,以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()
}

我不确定您开始使用location manager时使用的是什么,但我认为您可能需要考虑使用:

startMonitoringSignificantLocationChanges()

启动您的位置管理器。以下是苹果公司关于此主题的文档:

我不确定您开始使用location manager时使用的是什么,但我认为您可能希望使用:

startMonitoringSignificantLocationChanges()

启动您的位置管理器。以下是苹果公司关于该主题的文档:

如果您只针对iOS 9,请查看新的
requestLocation()
方法。它解决了你的问题。如果需要针对较旧版本的iOS,可以将
stopMonitoringLocation()
添加到

func locationManager(
    manager: CLLocationManager!, 
    didUpdateLocations locations: [AnyObject]!
)

一旦您得到一个读数,这将停止监视…

如果您只针对iOS 9,请查看新的
requestLocation()
方法。它解决了你的问题。如果需要针对较旧版本的iOS,可以将
stopMonitoringLocation()
添加到

func locationManager(
    manager: CLLocationManager!, 
    didUpdateLocations locations: [AnyObject]!
)
一旦你得到一个读数,这将停止监控