我想按照这个谷歌地图教程:http://www.raywenderlich.com/81103/introduction-google-maps-ios-sdk-swiftCLLocation经理不工作的iOS 8
和很多人一样我都创下了路障,其中CLLocationManager
似乎不火startUpdatingLocation()
。
我已更新pList
NSLocationAlwaysUsageDescription
和NSLocationWhenInUseUsageDescription
根据Location Services not working in iOS 8,但仍然没有被解雇的位置。下面
码 - 任何帮助表示赞赏!
import UIKit
class MapViewController: UIViewController, TypesTableViewControllerDelegate, CLLocationManagerDelegate {
@IBOutlet weak var mapView: GMSMapView!
@IBOutlet weak var mapCenterPinImage: UIImageView!
@IBOutlet weak var pinImageVerticalConstraint: NSLayoutConstraint!
var searchedTypes = ["bakery", "bar", "cafe", "grocery_or_supermarket", "restaurant"]
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "Types Segue" {
let navigationController = segue.destinationViewController as UINavigationController
let controller = segue.destinationViewController.topViewController as TypesTableViewController
controller.selectedTypes = searchedTypes
controller.delegate = self
}
}
// MARK: - Types Controller Delegate
func typesController(controller: TypesTableViewController, didSelectTypes types: [String]) {
searchedTypes = sorted(controller.selectedTypes)
dismissViewControllerAnimated(true, completion: nil)
}
func locationManager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
if status == .AuthorizedWhenInUse {
println("success") // Works
locationManager.startUpdatingLocation() // Does not seem to fire
mapView.myLocationEnabled = true
mapView.settings.myLocationButton = true
}
}
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
println("test") // Does not work
println(locations.count) // Does not work
if let location = locations.first as? CLLocation {
mapView.camera = GMSCameraPosition(target: location.coordinate, zoom: 15, bearing: 0, viewingAngle: 0)
locationManager.stopUpdatingLocation()
}
}
}
的 可能的复制http://stackoverflow.com/questions/24062509/location-services-not-working-in-ios-8?lq=1 – 2015-04-01 12:25:25
Hernant - 同意。这就是为什么我在问题中提到它。代码是好的,但问题是你必须改变你在哪里模拟你的'didUpdateLocations'的位置来触发。在提到的问题中没有提到。 其他人可能会面临同样的问题 - 避免 - 我会保持这个问题开 – 2015-04-01 12:40:53