本文整理汇总了Java中com.google.android.gms.location.FusedLocationProviderClient类的典型用法代码示例。如果您正苦于以下问题:Java FusedLocationProviderClient类的具体用法?Java FusedLocationProviderClient怎么用?Java FusedLocationProviderClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FusedLocationProviderClient类属于com.google.android.gms.location包,在下文中一共展示了FusedLocationProviderClient类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerForLocationUpdates
import com.google.android.gms.location.FusedLocationProviderClient; //导入依赖的package包/类
@DebugLog
@SuppressLint("MissingPermission")
void registerForLocationUpdates() {
FusedLocationProviderClient locationProviderClient = getFusedLocationProviderClient();
LocationRequest locationRequest = LocationRequest.create();
Looper looper = Looper.myLooper();
locationProviderClient.requestLocationUpdates(locationRequest, locationCallback, looper);
}
示例2: getFusedLocationProviderClient
import com.google.android.gms.location.FusedLocationProviderClient; //导入依赖的package包/类
@DebugLog
@NonNull
private FusedLocationProviderClient getFusedLocationProviderClient() {
if (fusedLocationProviderClient == null) {
fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(getActivity());
}
return fusedLocationProviderClient;
}
示例3: PositionProvider
import com.google.android.gms.location.FusedLocationProviderClient; //导入依赖的package包/类
private PositionProvider(Context context) {
Log.d(TAG, "Constructor");
fusedLocationProviderClient = new FusedLocationProviderClient(context);
locationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
Log.d(TAG, "onLocationResult");
onLocationChanged(locationResult.getLastLocation());
}
};
listeners = new SortedList<>(PositionProviderListener.class, new InnerCallback());
buildGoogleApiClient(context);
Location location = new Location("");
double last_latitude = Double.longBitsToDouble(TranSappApplication.getAppSharedPreferences()
.getLong(PositionProvider.USER_LATITUDE, 0));
last_latitude = last_latitude != 0 ? last_latitude : Constants.santiagoLatitude;
double last_longitude = Double.longBitsToDouble(TranSappApplication.getAppSharedPreferences()
.getLong(PositionProvider.USER_LONGITUDE, 0));
last_longitude = last_longitude != 0 ? last_longitude : Constants.santiagoLongitude;
Log.d(TAG, "load latitude: " + last_latitude);
Log.d(TAG, "load longitude: " + last_longitude);
location.setLatitude(last_latitude);
location.setLongitude(last_longitude);
lasKnownLocation = location;
}
示例4: RequestLocationResultObservable
import com.google.android.gms.location.FusedLocationProviderClient; //导入依赖的package包/类
public RequestLocationResultObservable(FusedLocationProviderClient client, LocationRequest request) {
this.client = client;
this.request = request;
}
示例5: RequestLocationAvailabilityObservable
import com.google.android.gms.location.FusedLocationProviderClient; //导入依赖的package包/类
public RequestLocationAvailabilityObservable(FusedLocationProviderClient client, LocationRequest
request) {
this.client = client;
this.request = request;
}
示例6: updateTransitionsByLastKnownLocation
import com.google.android.gms.location.FusedLocationProviderClient; //导入依赖的package包/类
@SuppressLint("MissingPermission")
void updateTransitionsByLastKnownLocation(final boolean startEventsHandler) {
try {
if (Permissions.checkLocation(context) && (mGoogleApiClient != null) && mGoogleApiClient.isConnected()) {
PPApplication.logE("GeofenceScanner.updateTransitionsByLastKnownLocation", "xxx");
FusedLocationProviderClient fusedLocationClient = LocationServices.getFusedLocationProviderClient(context);
final Context appContext = context.getApplicationContext();
//noinspection MissingPermission
fusedLocationClient.getLastLocation().addOnSuccessListener(new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
// Got last known location. In some rare situations this can be null.
PPApplication.logE("GeofenceScanner.updateTransitionsByLastKnownLocation", "onSuccess");
if (location != null) {
synchronized (PPApplication.geofenceScannerLastLocationMutex) {
lastLocation.set(location);
}
PPApplication.startHandlerThread();
final Handler handler = new Handler(PPApplication.handlerThread.getLooper());
handler.post(new Runnable() {
@Override
public void run() {
PowerManager powerManager = (PowerManager) appContext.getSystemService(POWER_SERVICE);
PowerManager.WakeLock wakeLock = null;
if (powerManager != null) {
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "GeofenceScanner.updateTransitionsByLastKnownLocation");
wakeLock.acquire(10 * 60 * 1000);
}
updateGeofencesInDB();
if (startEventsHandler) {
// start job
//EventsHandlerJob.startForSensor(appContext, EventsHandler.SENSOR_TYPE_LOCATION_MODE);
EventsHandler eventsHandler = new EventsHandler(appContext);
eventsHandler.handleEvents(EventsHandler.SENSOR_TYPE_LOCATION_MODE/*, false*/);
}
if ((wakeLock != null) && wakeLock.isHeld())
wakeLock.release();
}
});
}
}
});
}
} catch (Exception ignored) {}
}