החל מ-27 במרץ 2025, מומלץ להשתמש ב-android-latest-release
במקום ב-aosp-main
כדי ליצור תרומות ל-AOSP. מידע נוסף זמין במאמר שינויים ב-AOSP.
הגבלת מיקומים זמניים
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
כשאפליקציה מבקשת את המיקום של המכשיר, היא יכולה להמתין לתשובה לבקשה או לקבל עדכון מיקום באופן אופורטוניסטי באמצעות מאזינים פעילים למיקום. האפשרות הזו הייתה זמינה (ללא הגבלה) ב-Android 9 וגרסאות ישנות יותר, והיא סופקה כשאפליקציה ציינה רק את קצב העדכונים הפעיל של המיקום, והשאיר את הקצב הפסיבי ריק.
(משתמשים שמאזינים למיקום באופן פסיבי לא מקבלים עדכוני מיקום יזומים כי הם לא מציינים קצב עדכון מיקום).
החל מ-Android 10, כדי לקבל עדכוני מיקום באופן יזום, המפתחים צריכים לציין שהם זקוקים לעדכוני מיקום פסיביים מהקלאס FusedLocationProviderClient
.
ספק מיקום משולב
אפליקציות יכולות לציין את התדירות שבה הן מקבלות עדכוני מיקום מזדמנים מהקלאס FusedLocationProviderClient
בשתי דרכים.
השפעה
אם לא תספקו ערך ל-setFastestInterval
, יכול להיות שתהיה ירידה משמעותית במספר עדכוני המיקום שיועברו לאפליקציה.
הטמעה
כדי להטמיע את התכונה הזו, צריך רק להשתמש בערכים המוצעים לשיטה setFastestInterval
של הכיתה FusedLocationProviderClient
.
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-27 (שעון UTC).
[[["התוכן קל להבנה","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"]],["עדכון אחרון: 2025-07-27 (שעון UTC)."],[],[],null,["# Restrict opportunistic locations\n\nWhen an app requests a device's location, it can either wait for\nthe request response or, by using active location listeners, get an\nopportunistic location update. This was available (unrestricted) in\nAndroid 9 and lower, and was provided when an app specified only\nthe active location update rate, leaving the passive rate blank.\n(Passive location listeners don't receive opportunistic location\nupdates because they don't specify a location update rate.)\n\nStarting in Android 10, to get opportunistic\nlocation updates, developers must specify that they need passive location\nupdates from the **[FusedLocationProviderClient](https://developers.google.com/android/reference/com/google/android/gms/location\n/FusedLocationProviderClient)** class.\n\nFused location provider\n-----------------------\n\nApps can specify the rate at which they get opportunistic location updates from the [FusedLocationProviderClient](https://developers.google.com/android/reference/com/google/android/gms/location/FusedLocationProviderClient)\nclass in two ways.\n\n- Specify a value in the [setFastestInterval](https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.html#setFastestInterval(long)) method that's lower than the value of the [setInterval](https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.html#setInterval(long)) parameter. (Use a value of 0 ms or greater.)\n- Let the value be set automatically by leaving [setFastestInterval](https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.html#setFastestInterval(long)) unspecified.\n\nImpact\n------\n\nIf you don't provide a value for [setFastestInterval](https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.html#setFastestInterval(long)),\nyour app may experience a significant\nreduction in location updates delivered to it.\n\nImplementation\n--------------\n\nYou don't need to do anything to implement this feature other\nthan to use the suggested values for the [FusedLocationProviderClient](https://developers.google.com/android/reference/com/google/android/gms/location\n/FusedLocationProviderClient) class [setFastestInterval](https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.html#setFastestInterval(long))\nmethod."]]