选址错误 - Google Places API

6

我的代码出现了这个错误,我已经按照谷歌教程的步骤一步一步地进行操作了。

Pick Place error: The operation couldn’t be completed. The Places API could not find the user's location. This may be because the user has not allowed the application to access location information.

我已经将相关信息添加到info.plist中,我的代码如下 -
import UIKit
import GooglePlaces

class ViewController: UIViewController {

    var placesClient: GMSPlacesClient!

    @IBOutlet var nameLabel: UILabel!
    @IBOutlet var addressLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        let locationManager = CLLocationManager()
        locationManager.requestWhenInUseAuthorization()
        locationManager.startUpdatingLocation()
        placesClient = GMSPlacesClient.shared()
    }

    @IBAction func getCurrentPlace(_ sender: UIButton) {


        placesClient.currentPlace(callback: { (placeLikelihoodList, error) -> Void in
            if let error = error {
                print("Pick Place error: \(error.localizedDescription)")
                return
            }

            self.nameLabel.text = "No current place"
            self.addressLabel.text = ""

            if let placeLikelihoodList = placeLikelihoodList {
                let place = placeLikelihoodList.likelihoods.first?.place
                if let place = place {
                    self.nameLabel.text = place.name
                    self.addressLabel.text = place.formattedAddress?.components(separatedBy: ", ")
                        .joined(separator: "\n")
                }
            }
            }
        )
    }

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



}

位置窗口中的允许/拒绝选项消失得太快,即使我按下允许也没有任何反应,我不知道如何解决这个问题,因为我只是按照谷歌文档的说明操作。

此外,还出现了以下错误 -

2017-03-26 14:38:27.472739 Restaurant[26616:2797750] subsystem: com.apple.BackBoardServices.fence, category: Observer, enable_level: 1, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0, enable_private_data: 0
1个回答

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接