gpt4 book ai didi

ios - 解包 GMSPlacesClient 类型的可选值时意外发现 nil

转载 作者:行者123 更新时间:2023-11-30 13:19:18 26 4
gpt4 key购买 nike

我试图将我的谷歌地图 View 集中在用户当前位置,但是由于地方客户端等于nil,尽管我将gpsCoordinates分配给它,但我遇到了麻烦,下面是我的viewdidload()内的代码 View Controller

var gmsPlace : GMSPlace?
var gpsCoordinates : CLLocationCoordinate2D?

override func viewDidLoad() {
super.viewDidLoad()
//placesClient = GMSPlacesClient()
var placesClient = GMSPlacesClient.sharedClient()
placesClient.currentPlaceWithCallback { (placeLikelihoods, error) -> Void in
guard error == nil else {
print("Current Place error: \(error!.localizedDescription)")
return
}
var gmsPlace : GMSPlace?

if let placeLikelihoods = placeLikelihoods {
for likelihood in placeLikelihoods.likelihoods {
gmsPlace = likelihood.place
//print("Current Place name \(gmsPlace.name) at likelihood \(likelihood.likelihood)")
//print("Current Place address \(gmsPlace.formattedAddress)")
//print("Current Place attributions \(gmsPlace.attributions)")
//print("Current PlaceID \(gmsPlace.placeID)")
self.gpsCoordinates = (gmsPlace!.coordinate)

}
print(self.gpsCoordinates)

}
}
let testObject = PFObject(className: "TestObject")
testObject["foo"] = "bar"
testObject.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in
print("Object has been saved.")
}
let camera = GMSCameraPosition.cameraWithTarget(gpsCoordinates!, zoom: 16.9)
//let camera = GMSCamera
print(camera)
viewMap.camera = camera
viewMap.myLocationEnabled = true
viewMap.settings.myLocationButton = true


let marker = GMSMarker()
marker.position = self.gpsCoordinates!
marker.title = "Newport Beach"
marker.snippet = "California"
marker.map = viewMap

// Do any additional setup after loading the view, typically from a nib.
print(url)
print(videoData)
print(doUpload)
print(FriendsOrPublic)
print(dataPath)
if doUpload == true {
Upload()
}

// Download()
}

最佳答案

您好,只要在 View 中执行此操作就会出现您的问题将得到解决

关于ios - 解包 GMSPlacesClient 类型的可选值时意外发现 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37915650/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com