2015-04-01 86 views
0

我想按照这个谷歌地图教程:http://www.raywenderlich.com/81103/introduction-google-maps-ios-sdk-swiftCLLocation经理不工作的iOS 8

和很多人一样我都创下了路障,其中CLLocationManager似乎不火startUpdatingLocation()

我已更新pListNSLocationAlwaysUsageDescriptionNSLocationWhenInUseUsageDescription根据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() 
     } 
    } 
} 
+0

的 可能的复制http://stackoverflow.com/questions/24062509/location-services-not-working-in-ios-8?lq=1 – 2015-04-01 12:25:25

+0

Hernant - 同意。这就是为什么我在问题中提到它。代码是好的,但问题是你必须改变你在哪里模拟你的'didUpdateLocations'的位置来触发。在提到的问题中没有提到。 其他人可能会面临同样的问题 - 避免 - 我会保持这个问题开 – 2015-04-01 12:40:53

回答

0

令人难以置信。经过一天的测试,我找到了解决方案。代码很好。 仿真要求您更改位置

步骤:

  1. 在Xcode的模拟器 - >调试 - >位置 - >苹果(或任何..)
  2. 重办模拟

谷歌地图将现在在哪里,你选择你的仿真设置 中心(Xcode中 - >编辑计划 - >允许 模拟+默认位置=纽约)

希望这可以帮助别人!

0

代码似乎也没关系,你刚才提到你已经更新info.plist中。你可以检查“requestAlwaysAuthorization”而不是“requestWhenInUseAuthorization”。希望它可以解决你的问题。

您也可以参考这个链接 - http://nevan.net/2014/09/core-location-manager-changes-in-ios-8/

+0

这将是其他人更有帮助解决这个问题,如果你想补充的是什么与此代码段做了一些解释,以及它将如何解决问题。 – Brian 2015-04-01 21:35:05

相关问题