i attempting upload current users location parse cannot retrieve current users location. following tutorial here , have copied of necessary code straight there receiving error: current place error: operation couldn’t completed. places api ios not enabled. see developer's guide (https://developers.google.com/places/ios/start) how enable google places api ios.
below following viewdidload 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 // additional setup after loading view, typically 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 { likelihood in placelikelihoods.likelihoods { place = likelihood.place print("current place name \(place.name) @ 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") } } } } }
follow these steps enable google places api ios , google maps sdk ios in project on google developers console. if project doesn't have ios key (a type of api key), these instructions create new api key.
- go google developers console.
- create or select project.
- click continue enable both google places api ios , google maps sdk ios.
- on credentials page, ios key , set api credentials. note: if have existing ios key, may use key. can use same key of ios applications within same project.
- enter app's bundle identifier when prompted. example: com.example.hello-places.
click create. new ios key appears in list of api keys project. api key string of characters, this:
aizasybdvl-cticswykrz95suvnw7dbmudt1kg0
note: need enable maps service in google developer console. in new layout, choose apis & auth section , apis subitem in left column. next, in right 1 enable maps sdk ios clicking on off button.
to find local business or other place device located, call gmsplacesclient currentplacewithcallback:
. include callback method handle results.
the following code sample retrieves list of places device located, , logs name, likelihood, , other details each place.
placesclient.currentplacewithcallback({ (placelikelihoods, error) -> void in guard error == nil else { print("current place error: \(error!.localizeddescription)") return } if let placelikelihoods = placelikelihoods { likelihood in placelikelihoods.likelihoods { let place = likelihood.place print("current place name \(place.name) @ likelihood \(likelihood.likelihood)") print("current place address \(place.formattedaddress)") print("current place attributions \(place.attributions)") print("current placeid \(place.placeid)") } } })
here's related ticket discuss how current location: get user's current location / coordinates