// Specify the place data types to return.letfields:GMSPlaceField=GMSPlaceField(rawValue:UInt(GMSPlaceField.name.rawValue)|UInt(GMSPlaceField.placeID.rawValue))!placesClient?.findPlaceLikelihoodsFromCurrentLocation(withPlaceFields:fields,callback:{(placeLikelihoodList:Array<GMSPlaceLikelihood>?,error:Error?)inifleterror=error{print("An error occurred: \(error.localizedDescription)")return}ifletplaceLikelihoodList=placeLikelihoodList{forlikelihoodinplaceLikelihoodList{letplace=likelihood.placeprint("Current Place name \(String(describing:place.name)) at likelihood \(likelihood.likelihood)")print("Current PlaceID \(String(describing:place.placeID))")}}})
Objective-C
// Specify the place data types to return.GMSPlaceFieldfields=(GMSPlaceFieldName|GMSPlaceFieldPlaceID);[_placesClientfindPlaceLikelihoodsFromCurrentLocationWithPlaceFields:fieldscallback:^(NSArray<GMSPlaceLikelihood*>*_Nullablelikelihoods,NSError*_Nullableerror){if(error!=nil){NSLog(@"An error occurred %@",[errorlocalizedDescription]);return;}if(likelihoods!=nil){for(GMSPlaceLikelihood*likelihoodinlikelihoods){GMSPlace*place=likelihood.place;NSLog(@"Current place name: %@",place.name);NSLog(@"Place ID: %@",place.placeID);}}}];
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-17。"],[],[],null,["# Current Place\n\nUsing the Places SDK for iOS, you can discover the place where the\ndevice is currently located. That is, the place at the device's\ncurrently-reported location. Examples of places include local businesses,\npoints of interest, and geographic locations.\n\n1. [Request location authorization](#permissions)\n2. [Usage limits](#quota)\n3. [Get the current location](#get-current)\n4. [Display attributions in your app](#attributions)\n\nRequesting location authorization\n---------------------------------\n\nIf your app uses\n[`GMSPlacesClient findPlaceLikelihoodsFromCurrentLocationWithPlaceFields:`](/maps/documentation/places/ios-sdk/reference/objc/Classes/GMSPlacesClient#-findplacelikelihoodsfromcurrentlocationwithplacefields:callback:),\nyour app must request permission to use location services. Add the\n`NSLocationWhenInUseUsageDescription` key to your `Info.plist`\nfile, to define the string informing the user why you need the location\nservices. For example: \n\n```text\n\u003ckey\u003eNSLocationWhenInUseUsageDescription\u003c/key\u003e\n\u003cstring\u003eShow your location on the map\u003c/string\u003e\n```\n\nIf you want to call\n[`findPlaceLikelihoodsFromCurrentLocationWithPlaceFields:`](/maps/documentation/places/ios-sdk/reference/objc/Classes/GMSPlacesClient#-findplacelikelihoodsfromcurrentlocationwithplacefields:callback:) when\nthe app is in the background, without triggering a confirmation dialog, take\nthe following steps prior to making the call:\n\n1. Add the `NSLocationAlwaysUsageDescription` key to your `Info.plist`file.\n2. Call `requestAlwaysAuthorization` on any instance of `CLLocationManager` before calling the method.\n\nRequest authorization from `CLLocationManager` as follows: \n\n### Swift\n\n```swift\n locationManager.requestAlwaysAuthorization()\n \n```\n\n### Objective-C\n\n```objective-c\n [self.locationManager requestAlwaysAuthorization];\n \n```\n\nGetting the current location\n----------------------------\n\n| **Note:** iOS 14 introduced a new privacy feature where users can choose to share their approximate, rather than precise, location. Check your app's value of [accuracyAuthorization](https://developer.apple.com/documentation/corelocation/cllocationmanager/3600215-accuracyauthorization) in `CLLocationManager` so your app behaves appropriately. [See this video for more information.](https://developer.apple.com/videos/play/wwdc2020/10162/)\n\nTo find the local business or other place where the device is currently\nlocated, call\n[`GMSPlacesClient\nfindPlaceLikelihoodsFromCurrentLocationWithPlaceFields:`](/maps/documentation/places/ios-sdk/reference/objc/Classes/GMSPlacesClient#-findplacelikelihoodsfromcurrentlocationwithplacefields:callback:). Include\nthe following parameters:\n\n- One or more `GMSPlaceField`s, specifying which data types to return. If you omit this parameter, ALL possible fields will be returned, and you will be billed accordingly. This applies only to Place Details requests.\n- A callback method to handle the results.\n\n| **IMPORTANT!** `findPlaceLikelihoodsFromCurrentLocationWithPlaceFields:` does not support the following fields: `GMSPlaceFieldAddressComponents`, `GMSPlaceFieldOpeningHours`, `GMSPlaceFieldPhoneNumber`, and `GMSPlaceFieldWebsite`. Read more about [place data fields](/maps/documentation/places/ios-sdk/place-data-fields)\n\nFields correspond to Place Search results, and are divided into three billing categories:\nBasic, Contact, and Atmosphere. Basic fields are billed at base rate, and incur no additional\ncharges. Contact and Atmosphere fields are billed at a higher rate. For more information\nabout how Place data requests are billed, see\n[Usage and Billing](/maps/documentation/places/ios-sdk/usage-and-billing).\n\nThe API invokes the specified callback method, returning an array of\n[`GMSPlaceLikelihood`](/maps/documentation/places/ios-sdk/reference/objc/Classes/GMSPlaceLikelihood)\nobjects.\n\nEach\n[`GMSPlaceLikelihood`](/maps/documentation/places/ios-sdk/reference/objc/Classes/GMSPlaceLikelihood)\nobject represents a place. For each place, the result includes an\nindication of the likelihood that the place is the right one. A higher value\nmeans a greater probability that the place is the best match. The buffer may\nbe empty, if there is no known place corresponding to the device location.\n\nThe following code sample retrieves the list of places where the device is\nmost likely to be located, and logs the name and likelihood for each place. \n\n### Swift\n\n```swift\n// Specify the place data types to return.\nlet fields: GMSPlaceField = GMSPlaceField(rawValue: UInt(GMSPlaceField.name.rawValue) |\n UInt(GMSPlaceField.placeID.rawValue))!\nplacesClient?.findPlaceLikelihoodsFromCurrentLocation(withPlaceFields: fields, callback: {\n (placeLikelihoodList: Array\u003cGMSPlaceLikelihood\u003e?, error: Error?) in\n if let error = error {\n print(\"An error occurred: \\(error.localizedDescription)\")\n return\n }\n\n if let placeLikelihoodList = placeLikelihoodList {\n for likelihood in placeLikelihoodList {\n let place = likelihood.place\n print(\"Current Place name \\(String(describing: place.name)) at likelihood \\(likelihood.likelihood)\")\n print(\"Current PlaceID \\(String(describing: place.placeID))\")\n }\n }\n})\n```\n\n### Objective-C\n\n```objective-c\n// Specify the place data types to return.\nGMSPlaceField fields = (GMSPlaceFieldName | GMSPlaceFieldPlaceID);\n[_placesClient findPlaceLikelihoodsFromCurrentLocationWithPlaceFields:fields callback:^(NSArray\u003cGMSPlaceLikelihood *\u003e * _Nullable likelihoods, NSError * _Nullable error) {\n if (error != nil) {\n NSLog(@\"An error occurred %@\", [error localizedDescription]);\n return;\n }\n if (likelihoods != nil) {\n for (GMSPlaceLikelihood *likelihood in likelihoods) {\n GMSPlace *place = likelihood.place;\n NSLog(@\"Current place name: %@\", place.name);\n NSLog(@\"Place ID: %@\", place.placeID);\n }\n }\n}];\n```\n\nNotes about the likelihood values:\n\n- The likelihood provides a relative probability of the place being the best match within the list of returned places for a single request. You can't compare likelihoods across different requests.\n- The value of the likelihood will be between 0 and 1.0.\n- The sum of the likelihoods in a returned array of [`GMSPlaceLikelihood`](/maps/documentation/places/ios-sdk/reference/objc/Classes/GMSPlaceLikelihood) objects is always less than or equal to 1.0. Note that the sum isn't necessarily 1.0.\n\nFor example, to represent a 55% likelihood that the correct place is Place A,\nand a 35% likelihood that it's Place B, the likelihood array has two members:\nPlace A with a likelihood of 0.55 and\nPlace B with a likelihood of 0.35.\n\nDisplaying attributions in your app\n-----------------------------------\n\nWhen your app displays information obtained from\n[`GMSPlacesClient\nfindPlaceLikelihoodsFromCurrentLocationWithPlaceFields:`](/maps/documentation/places/ios-sdk/reference/objc/Classes/GMSPlacesClient#-findplacelikelihoodsfromcurrentlocationwithplacefields:callback:), the app\nmust also display attributions. Read more about\n[attributions](/maps/documentation/places/ios-sdk/attributions)."]]