为什么此功能不断循环?

小的
func centerMapOnLocation(location: CLLocation) {
    let coordinateRegion = MKCoordinateRegionMakeWithDistance(location.coordinate,
        regionRadius * 2.0, regionRadius * 2.0)
    MapOutlet.setRegion(coordinateRegion, animated: true)
}

尽管我从未编写任何循环代码,但下面的视图控制器中的该函数仍继续运行,有人可以帮助找出错误的逻辑。这是视图控制器的其余部分

import UIKit
import MapKit
import CoreLocation


class ViewControllerPublic: UIViewController, CLLocationManagerDelegate {
let locationManager = CLLocationManager()



let initialLocation = CLLocation(latitude: 3.632488, longitude: -117.898886)
override func viewDidLoad() {
    super.viewDidLoad()
    centerMapOnLocation(initialLocation)

    // Ask for Authorisation from the User.
    self.locationManager.requestAlwaysAuthorization()

    // For use in foreground
    self.locationManager.requestWhenInUseAuthorization()

    if CLLocationManager.locationServicesEnabled() {
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
        locationManager.startUpdatingLocation()
    }

}

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    let locValue:CLLocationCoordinate2D = manager.location!.coordinate
    print("locations = \(locValue.latitude) \(locValue.longitude)")
    let currentLocation = CLLocation(latitude: locValue.latitude, longitude: locValue.longitude)
    centerMapOnLocation(currentLocation)
}

let regionRadius: CLLocationDistance = 2300
func centerMapOnLocation(location: CLLocation) {
    let coordinateRegion = MKCoordinateRegionMakeWithDistance(location.coordinate,
        regionRadius * 2.0, regionRadius * 2.0)
    MapOutlet.setRegion(coordinateRegion, animated: true)
}

@IBOutlet weak var MapOutlet: MKMapView!

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}

pbush25

CLLocation manager就像@Ashish Kakkad所说那样,您永远不会使它无效,只要您进行了最细微的位置更改,您的函数就会再次被调用。如果您不希望出现这种情况,那么在找到位置后,didUpdateLocations您需要执行locationManager.stopUpdatingLocation()或者,如果您确实希望应用程序每次位置更改时都更新地图,则可能需要考虑更改所需的位置精度。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

为什么此相交功能不起作用?

来自分类Dev

为什么循环功能不能与空列表一起使用?

来自分类Dev

为什么此功能不确定?

来自分类Dev

为什么imagepicker程序js中的此功能不起作用?

来自分类Dev

为什么此功能不会立即失败?

来自分类Dev

为什么此控制器内的console.log和功能不起作用?

来自分类Dev

为什么此代码不断被“终止”?

来自分类Dev

为什么此功能不能正确打开和关闭LED?

来自分类Dev

为什么此Perl随机播放功能不能随机播放?

来自分类Dev

为什么此功能不起作用?

来自分类Dev

为什么此隐藏显示功能不起作用?

来自分类Dev

Haskell:为什么此功能会不断询问用户输入而不终止

来自分类Dev

为什么此功能不触发?

来自分类Dev

组装-为什么此CALL功能不起作用?

来自分类Dev

为什么for循环的行为与while循环的“ pop”功能不同?

来自分类Dev

为什么此功能不起作用?我希望它从10倒数到1

来自分类Dev

为什么此交换功能不起作用?(在C中交换字符串)

来自分类Dev

为什么解密功能中的此循环不起作用?

来自分类Dev

与地图相比,为什么此循环功能这么慢?

来自分类Dev

为什么此代码不断循环?(ActionListener的概念)

来自分类Dev

为什么此功能不输出小数

来自分类Dev

为什么此功能不能打印所有值?

来自分类Dev

为什么单击第二项后此单击功能不起作用?

来自分类Dev

为什么此功能不起作用,但是在Eclipse中却不显示错误?

来自分类Dev

PHP为什么此循环不断循环?

来自分类Dev

为什么此代码不断被“终止”?

来自分类Dev

为什么此功能不能正确打开和关闭LED?

来自分类Dev

为什么此归类排序功能不会导致无限循环?

来自分类Dev

为什么Linux中的“系统”功能不能运行此shellscript?

Related 相关文章

  1. 1

    为什么此相交功能不起作用?

  2. 2

    为什么循环功能不能与空列表一起使用?

  3. 3

    为什么此功能不确定?

  4. 4

    为什么imagepicker程序js中的此功能不起作用?

  5. 5

    为什么此功能不会立即失败?

  6. 6

    为什么此控制器内的console.log和功能不起作用?

  7. 7

    为什么此代码不断被“终止”?

  8. 8

    为什么此功能不能正确打开和关闭LED?

  9. 9

    为什么此Perl随机播放功能不能随机播放?

  10. 10

    为什么此功能不起作用?

  11. 11

    为什么此隐藏显示功能不起作用?

  12. 12

    Haskell:为什么此功能会不断询问用户输入而不终止

  13. 13

    为什么此功能不触发?

  14. 14

    组装-为什么此CALL功能不起作用?

  15. 15

    为什么for循环的行为与while循环的“ pop”功能不同?

  16. 16

    为什么此功能不起作用?我希望它从10倒数到1

  17. 17

    为什么此交换功能不起作用?(在C中交换字符串)

  18. 18

    为什么解密功能中的此循环不起作用?

  19. 19

    与地图相比,为什么此循环功能这么慢?

  20. 20

    为什么此代码不断循环?(ActionListener的概念)

  21. 21

    为什么此功能不输出小数

  22. 22

    为什么此功能不能打印所有值?

  23. 23

    为什么单击第二项后此单击功能不起作用?

  24. 24

    为什么此功能不起作用,但是在Eclipse中却不显示错误?

  25. 25

    PHP为什么此循环不断循环?

  26. 26

    为什么此代码不断被“终止”?

  27. 27

    为什么此功能不能正确打开和关闭LED?

  28. 28

    为什么此归类排序功能不会导致无限循环?

  29. 29

    为什么Linux中的“系统”功能不能运行此shellscript?

热门标签

归档