Save nearest establishment to google user account in Swift2

冷暖自知 提交于 2019-12-12 05:25:41

问题


The purpose for this portion of the app is for the user (signed in with Google sign in) to locate the nearest place to them and save it automatically to the user's google account.

The below method works fine, grabbing the most likely place the user is located at (first object in the array of placeLikelihoods). Now what I need to do is save it to the user's google account (the one they signed in with).

Any lead or ideas on how to do this or if it's even possible? Thank you for the help like always.

func getInfoViaPlacesClient() {

let placesClient = GMSPlacesClient.sharedClient()

placesClient.currentPlaceWithCallback { (likelihoodlist, error) -> Void in

    if error != nil {
        print("Current Place error: \(error!.localizedDescription)")
        return
    }

    let nearestPlace : GMSPlaceLikelihood = likelihoodlist!.likelihoods.first as! GMSPlaceLikelihood
        print(nearestPlace.likelihood)
        self.nearestPlace = nearestPlace.place

        self.saveNearestPlace()

  }   
}

Save method... I think I'm on the right track but I keep getting this error in the placesClient.addPlace block...

Add Place error: The operation couldn’t be completed. (com.google.places.server.ErrorDomain error -1.)

func saveNearestPlace() {

//to app(core data)
let placesClient = GMSPlacesClient.sharedClient()

let name = self.nearestPlace!.name
let address = self.nearestPlace!.formattedAddress

LocationController.sharedInstance.addLocationWithName(name!, address: address!)

//to google 

let addedPlace = GMSUserAddedPlace()
addedPlace.name = self.nearestPlace?.name
addedPlace.coordinate = (self.nearestPlace?.coordinate)!
addedPlace.types = self.nearestPlace?.types
addedPlace.address = self.nearestPlace?.formattedAddress

placesClient.addPlace(addedPlace, callback: { (place: GMSPlace?, error: NSError?) -> Void in

    if let error = error {
        print("Add Place error: \(error.localizedDescription)")
        return
    }

    if let place = place {

        self.nearestPlace = place

        print("Added place with placeID \(place.placeID)")
        print("Added Place name \(place.name)")
        print("Added Place address \(place.formattedAddress)")
    }
})

}

来源:https://stackoverflow.com/questions/34969241/save-nearest-establishment-to-google-user-account-in-swift2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!