I am attempting to upload the current users location to Parse however I cannot retrieve the current users location. I am following the tutorial here and have copied all of the necessary code straight from there however I am receiving the error: Current Place error: The operation couldn’t be completed. The Places API for iOS is not enabled. See the developer's guide (https://developers.google.com/places/ios/start) for how to enable the Google Places API for iOS.
Below is my following viewdidload as well as upload function.
@IBOutlet weak var viewMap: GMSMapView!
var placesClient: GMSPlacesClient?
override func viewDidLoad() {
super.viewDidLoad()
placesClient = GMSPlacesClient()
let testObject = PFObject(className: "TestObject")
testObject["foo"] = "bar"
testObject.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in
print("Object has been saved.")
}
let camera = GMSCameraPosition.cameraWithLatitude(33.600727, longitude: -117.900840, zoom: 16.9)
viewMap.camera = camera
viewMap.myLocationEnabled = true
viewMap.settings.myLocationButton = true
let marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(33.600727, -117.900840)
marker.title = "Newport Beach"
marker.snippet = "California"
marker.map = viewMap
// Do any additional setup after loading the view, typically from a nib.
Upload()
}
var gmsPlace : GMSPlace?
var gpsCoordinates : String?
func Upload() {
// var place : GMSPlace
var placesClient = GMSPlacesClient.sharedClient()
placesClient.currentPlaceWithCallback { (placeLikelihoods, error) -> Void in
guard error == nil else {
print("Current Place error: \(error!.localizedDescription)")
return
}
var place : GMSPlace
if let placeLikelihoods = placeLikelihoods {
for likelihood in placeLikelihoods.likelihoods {
place = likelihood.place
print("Current Place name \(place.name) at likelihood \(likelihood.likelihood)")
print("Current Place address \(place.formattedAddress)")
print("Current Place attributions \(place.attributions)")
print("Current PlaceID \(place.placeID)")
self.gpsCoordinates = (place.placeID)
print(self.path)
var videodata: NSData
videodata = (NSData.dataWithContentsOfMappedFile(self.path!) as? NSData)!
let file = PFFile(name:"upload.mp4", data:videodata)
let uploadedVideo = PFObject(className:"UploadedVideo")
uploadedVideo["GPS"] = self.gpsCoordinates
uploadedVideo["VideoFile"] = file
uploadedVideo.saveInBackground()
file!.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in print("File has been saved")
}
}
}
}
}