I am attempting to center my google maps view on the users current location however I am having trouble due to the placesClient being equal to nil although I assign the gpsCoordinates to it, below is my code inside of my viewdidload() of the 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()
}