1

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")
                }
            }
        }
    }

}
maz
  • 349
  • 2
  • 3
  • 15

5 Answers5

11

Follow these steps to enable the Google Places API for iOS and the Google Maps SDK for iOS in your project on the Google Developers Console. If your project doesn't already have an iOS key (a type of API key), these instructions also help you to create a new API key.

  • Go to the Google Developers Console.
  • Create or select a project.
  • Click Continue to enable both the Google Places API for iOS and the Google Maps SDK for iOS.
  • On the Credentials page, get an iOS key and set the API credentials. Note: If you have an existing iOS key, you may use that key. You can use the same key with any of your iOS applications within the same project.
  • Enter your app's bundle identifier when prompted. For example: com.example.hello-places.
  • Click Create. Your new iOS key appears in the list of API keys for your project. An API key is a string of characters, something like this:

    AIzaSyBdVl-cTICSwYKrZ95SuvNw7dbMuDt1KG0
    

Note: You need to enable maps service in Google developer Console. In new layout, choose APIs & auth section and APIs subitem in the left column. Next, in the right one enable Maps SDK for iOS by clicking on the Off button.

To find the local business or other place where the device is currently located, call GMSPlacesClient currentPlaceWithCallback:. Include a callback method to handle the results.

The following code sample retrieves the list of places where the device is most likely to be located, and logs the name, likelihood, and other details for each place.

placesClient.currentPlaceWithCallback({ (placeLikelihoods, error) -> Void in
      guard error == nil else {
        print("Current Place error: \(error!.localizedDescription)")
        return
      }

      if let placeLikelihoods = placeLikelihoods {
        for likelihood in placeLikelihoods.likelihoods {
          let 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)")
        }
      }
    })

Here's a related SO ticket which discuss how to get current location: Get User's Current Location / Coordinates

Community
  • 1
  • 1
Android Enthusiast
  • 4,826
  • 2
  • 15
  • 30
  • 1
    I've done all this but I still get 'The Places API for iOS is not enabled'. The API is definitely enabled. It's set for iOS. Not sure what to do. – Oliver Dixon Feb 21 '19 at 14:48
  • I have the same problem here.. The Places API is enabled but still same error as you have. I got stuck – mehmetsen80 Feb 21 '19 at 23:00
  • i have enabled placesAPI from console still i got this error NSLocalizedDescription=Places SDK for iOS has not been used in project 110476576428 before or it is disabled. if anyone have the solution please share here @OliverDixon – Swift Feb 25 '19 at 10:39
  • i have enabled placesAPI from console still i got this error NSLocalizedDescription=Places SDK for iOS has not been used in project 110476576428 before or it is disabled. if anyone have the solution please share here or post the answer. @mehmetsen80 – Swift Feb 25 '19 at 10:39
  • It looks like the places SDK for iOS had a bug in it :-| doing vanilla GET requests works with the key. So I'm not using the SDK anymore. – Oliver Dixon Feb 25 '19 at 10:41
9

Mostly you are using an old sdk version try upgrading.

Notice: Version 2.7.0 of the Places SDK for iOS is deprecated as of January 29, 2019, and will be turned off on July 29, 2019. A new version of the Places SDK for iOS is now available. We recommend updating to the new version as soon as possible. For details, see the migration guide.

pod ‘GooglePlaces’, ‘= 3.1.0’
pod ‘GooglePlacePicker’, ‘= 3.1.0’
pod ‘GoogleMaps’, ‘= 3.1.0’
Geo Joy
  • 347
  • 2
  • 10
4

Ok mine worked when I upgraded GooglePlaces, GooglePlacePicker and GoogleMaps SDK from 2.7.0 to 3.0.3 on the pod file

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

target 'ProjectName' do
  pod 'GooglePlaces', '= 3.0.3'
  pod 'GooglePlacePicker', '= 3.0.3'
  pod 'GoogleMaps', '= 3.0.3'
end

$ pod update

So if you are sure that you have already enabled the Google Places API on Google console then updating the versions in pod file might help.

mehmetsen80
  • 727
  • 1
  • 8
  • 25
  • @AbiramiBala Think twice when you downgrading and claiming something here that really exists. Go to the https://cocoapods.org/ then type Google Place you'll see all the 3.0.3 versions for Google Place Picker, GooglePlaces, Google Maps – mehmetsen80 Feb 26 '19 at 16:51
  • But when i try to update by "pod update" it is updateing to 2.7 only. And when i try to update pod like your code it gives the error like -> CocoaPods could not find compatible versions for pod "GoogleMaps": In Podfile: GoogleMaps (= 3.0.3). note: i didn't downvoted – Abirami Bala Feb 27 '19 at 05:59
  • @AbiramiBala Make sure you update your pod as well.. sudo gem install cocoapods – mehmetsen80 Feb 28 '19 at 18:39
  • updated again the same error, cocoapods could not the compatible version for Google Maps. check twice before you answer...! – Abirami Bala Mar 02 '19 at 07:21
  • @AbiramiBala You are downgrading my answer, still I am trying to give you options, then you are still sarcastic. Good luck. – mehmetsen80 Mar 04 '19 at 00:25
2

This was an issue with version GooglePlaces 2.5.0.

I had not updated my local pod repo so the default version was 2.5.0. After running pod repo update, the version 3.0.3 worked.

lovelikelando
  • 7,593
  • 6
  • 32
  • 50
0

Go to https://console.cloud.google.com/apis/library

(Make sure you are on the correct project, listed on the top left)

Search for and select: 'Places SDK for iOS'.

Click 'Enable' button.

AG Liber
  • 9
  • 1