این محصول یا ویژگی در وضعیت Legacy است. برای اطلاعات بیشتر درباره وضعیت Legacy به محصولات و ویژگی های Legacy مراجعه کنید. برای مهاجرت به Places API برای iOS (جدید)، به راهنمای مهاجرت مراجعه کنید.
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
با استفاده از Places SDK برای iOS، می توانید مکانی را که دستگاه در حال حاضر در آن قرار دارد، پیدا کنید. یعنی مکانی در مکان گزارش شده دستگاه در حال حاضر. نمونههایی از مکانها شامل مشاغل محلی، نقاط دیدنی و مکانهای جغرافیایی است.
اگر برنامه شما از GMSPlacesClient findPlaceLikelihoodsFromCurrentLocationWithPlaceFields: برنامه شما باید برای استفاده از خدمات مکان درخواست مجوز کند. کلید NSLocationWhenInUseUsageDescription را به فایل Info.plist خود اضافه کنید تا رشته ای را تعریف کنید که به کاربر اطلاع می دهد چرا به خدمات مکان نیاز دارید. به عنوان مثال:
<key>NSLocationWhenInUseUsageDescription</key>
<string>Show your location on the map</string>
یک یا چند عدد GMSPlaceField که مشخص می کند کدام نوع داده را برگرداند. اگر این پارامتر را حذف کنید، تمام فیلدهای ممکن برگردانده می شوند و بر اساس آن صورتحساب به شما تعلق می گیرد. این فقط برای درخواستهای جزئیات مکان اعمال میشود.
روشی برای کنترل نتایج.
فیلدها با نتایج جستجوی مکان مطابقت دارند و به سه دسته صورتحساب تقسیم می شوند: Basic، Contact، و Atmosphere. فیلدهای اصلی با نرخ پایه صورتحساب میشوند و هیچ هزینه اضافی متحمل نمیشوند. فیلدهای تماس و جو با نرخ بالاتری صورتحساب میشوند. برای اطلاعات بیشتر درباره نحوه صدور صورتحساب درخواستهای داده مکان، استفاده و صورتحساب را ببینید.
API روش برگشت تماس مشخص شده را فراخوانی می کند و آرایه ای از اشیاء GMSPlaceLikelihood را برمی گرداند.
هر شی GMSPlaceLikelihood یک مکان را نشان می دهد. برای هر مکان، نتیجه شامل نشانه ای از احتمال درست بودن مکان است. مقدار بالاتر به معنای احتمال بیشتر است که مکان بهترین تطابق است. اگر مکان شناخته شده ای برای مکان دستگاه وجود نداشته باشد، ممکن است بافر خالی باشد.
نمونه کد زیر فهرستی از مکانهایی را بازیابی میکند که احتمالاً دستگاه در آنها قرار دارد، و نام و احتمال هر مکان را ثبت میکند.
سویفت
// 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))")}}})
هدف-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);}}}];
نکاتی در مورد مقادیر احتمال:
احتمال یک احتمال نسبی را فراهم می کند که مکان بهترین مطابقت در لیست مکان های برگشتی برای یک درخواست واحد باشد. شما نمی توانید احتمالات را در درخواست های مختلف مقایسه کنید.
مقدار احتمال بین 0 تا 1.0 خواهد بود.
مجموع احتمالات در یک آرایه برگشتی از اشیاء GMSPlaceLikelihood همیشه کمتر یا مساوی 1.0 است. توجه داشته باشید که مجموع لزوماً 1.0 نیست.
به عنوان مثال، برای نشان دادن احتمال 55٪ که مکان صحیح مکان A است، و احتمال 35٪ که مکان B است، آرایه احتمال دارای دو عضو است: مکان A با احتمال 0.55 و مکان B با احتمال 0.35.
تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی."],[],[],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)."]]