本文整理汇总了Java中com.google.android.gms.location.LocationResult类的典型用法代码示例。如果您正苦于以下问题:Java LocationResult类的具体用法?Java LocationResult怎么用?Java LocationResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LocationResult类属于com.google.android.gms.location包,在下文中一共展示了LocationResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onReceive
import com.google.android.gms.location.LocationResult; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
prefs = Utils.getPrefs(context);
switch (intent.getAction()) {
case Intent.ACTION_BOOT_COMPLETED:
case ACTION_START_LOCATION:
apiClient = new GoogleApiClient.Builder(context)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
apiClient.connect();
break;
case ACTION_LOCATION_UPDATE:
if (prefs.getBoolean(Common.PREF_ENABLE_LOCATION_TRACKING, false) && LocationResult.hasResult(intent)) {
LocationResult result = LocationResult.extractResult(intent);
Location location = result.getLastLocation();
if (location != null)
logLocation(location, context);
}
break;
}
}
示例2: requestLocationRequestUpdates
import com.google.android.gms.location.LocationResult; //导入依赖的package包/类
@NonNull
@RequiresPermission(
anyOf = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission" +
".ACCESS_FINE_LOCATION"}
)
public Observable<LocationResult> requestLocationRequestUpdates(LocationRequest request) {
return ObservableTask.create(callback -> {
LocationCallback resultCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult result) {
super.onLocationResult(result);
callback.onNext(result);
}
};
callback.setDisposeListener(() -> client.removeLocationUpdates(resultCallback));
return client.requestLocationUpdates(request, resultCallback, null);
});
}
示例3: onReceive
import com.google.android.gms.location.LocationResult; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null) {
final String action = intent.getAction();
if (ACTION_PROCESS_UPDATES.equals(action)) {
LocationResult result = LocationResult.extractResult(intent);
if (result != null) {
List<Location> locations = result.getLocations();
LocationResultHelper locationResultHelper = new LocationResultHelper(
context, locations);
// Save the location data to SharedPreferences.
locationResultHelper.saveResults();
// Show notification with the location data.
locationResultHelper.showNotification();
Log.i(TAG, LocationResultHelper.getSavedLocationResult(context));
}
}
}
}
开发者ID:googlecodelabs,项目名称:background-location-updates-android-o,代码行数:20,代码来源:LocationUpdatesBroadcastReceiver.java
示例4: onHandleIntent
import com.google.android.gms.location.LocationResult; //导入依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
if (intent != null) {
final String action = intent.getAction();
if (ACTION_PROCESS_UPDATES.equals(action)) {
LocationResult result = LocationResult.extractResult(intent);
if (result != null) {
List<Location> locations = result.getLocations();
LocationResultHelper locationResultHelper = new LocationResultHelper(this,
locations);
// Save the location data to SharedPreferences.
locationResultHelper.saveResults();
// Show notification with the location data.
locationResultHelper.showNotification();
Log.i(TAG, LocationResultHelper.getSavedLocationResult(this));
}
}
}
}
开发者ID:googlecodelabs,项目名称:background-location-updates-android-o,代码行数:20,代码来源:LocationUpdatesIntentService.java
示例5: onCreate
import com.google.android.gms.location.LocationResult; //导入依赖的package包/类
@Override
public void onCreate() {
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
locationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
super.onLocationResult(locationResult);
onNewLocation(locationResult.getLastLocation());
}
};
createLocationRequest();
getLastLocation();
HandlerThread handlerThread = new HandlerThread(TAG);
handlerThread.start();
serviceHandler = new Handler(handlerThread.getLooper());
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
}
示例6: onHandleIntent
import com.google.android.gms.location.LocationResult; //导入依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
if (mPreferenceUtils.isActivityUpdatesStarted()) {
if (mPreferenceUtils.isLocationUpdatesStarted()) {
if (LocationResult.hasResult(intent)) {
LocationResult locationResult = LocationResult.extractResult(intent);
Location location = locationResult.getLastLocation();
saveLocation(location);
}
long currentTime = System.currentTimeMillis();
long tolerance = mPreferenceUtils.getActivityRecognitionToleranceMillis();
long lastActivityTime = mPreferenceUtils.getLastActivityTime();
long elapsedTime = currentTime - lastActivityTime;
if (elapsedTime > tolerance) {
mLocationUpdatesController.stopLocationUpdates();
}
}
}
}
示例7: createLocationCallback
import com.google.android.gms.location.LocationResult; //导入依赖的package包/类
private void createLocationCallback() {
mLocationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
super.onLocationResult(locationResult);
mCurrentLocation = locationResult.getLastLocation();
setLatLong(mCurrentLocation);
//Toast.makeText(MainActivity.this, "GPS Update", Toast.LENGTH_SHORT).show();
}
};
}
示例8: createLocationCallback
import com.google.android.gms.location.LocationResult; //导入依赖的package包/类
public void createLocationCallback() {
mLocationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
super.onLocationResult(locationResult);
mCurrentLocation = locationResult.getLastLocation();
setLatLong(mCurrentLocation);
}
};
}
示例9: createLocationCallback
import com.google.android.gms.location.LocationResult; //导入依赖的package包/类
/**
* Creates a callback for receiving location events.
*/
private void createLocationCallback() {
mLocationCallback = new LocationCallback() {
@Override
public void onLocationResult(final LocationResult locationResult) {
super.onLocationResult(locationResult);
if (mRequestingLocationUpdates) {
Log.i(TAG, "update event");
Location oldLocation = mCurrentLocation;
mCurrentLocation = locationResult.getLastLocation();
if (initialPosition == null) {
initialPosition = mCurrentLocation;
map.moveCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(initialPosition.getLatitude(),
initialPosition.getLongitude()), DEFAULT_ZOOM));
Log.d("INITIAL_POSITION", initialPosition.getLatitude() + " " +
initialPosition.getLongitude());
createAndDrawPath();
}
mLastUpdateTime = DateFormat.getTimeInstance().format(new Date());
updateUI(oldLocation);
}
}
};
}
示例10: onLocationResult
import com.google.android.gms.location.LocationResult; //导入依赖的package包/类
@Override public void onLocationResult(LocationResult locationResult) {
for (Location location : locationResult.getLocations()) {
Log.i("Debug ", "On Location Available " + location.toString());
currentLocation = location;
matchForCheckPoints();
}
}
示例11: onLocationResult
import com.google.android.gms.location.LocationResult; //导入依赖的package包/类
@DebugLog
@Override
public void onLocationResult(LocationResult locationResult) {
super.onLocationResult(locationResult);
Location lastLocation = locationResult.getLastLocation();
updatePosition(lastLocation);
}
示例12: onStartCommand
import com.google.android.gms.location.LocationResult; //导入依赖的package包/类
@WorkerThread
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
count++;
if (LocationResult.hasResult(intent)) {
// 從fusedLocationApi取得位置資料
LocationResult locationResult = LocationResult.extractResult(intent);
Location location = locationResult.getLastLocation();
if (location != null) {
succeed++;
// 若小於最小間距,則不紀錄該航跡
if (mTrkpts.size() > 1) {
double interval = SphericalUtil.computeDistanceBetween(
new LatLng(location.getLatitude(), location.getLongitude()),
new LatLng(mLastPosition.getLatitude(), mLastPosition.getLongitude()));
if (interval < DISTANCE_INTERVAL_FOR_TRKPTS)
return START_STICKY;
}
mTrkpts.add(location);
mLastPosition = location;
// Send Location Update to Activity
if (callBack != null)
callBack.getServiceData(location);
}
}
// Message for testing
Log.d(TAG, "Record Times: " + count + ", Succeed times: " + succeed +
", Points number: " + mTrkpts.size()
+ ", Time from start: " + (new Date().getTime() - startTime) / 1000);
return START_STICKY;
}
示例13: onReceive
import com.google.android.gms.location.LocationResult; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
if (LocationResult.hasResult(intent)) {
LocationResult locationResult = LocationResult.extractResult(intent);
Location location = locationResult.getLastLocation();
if (location != null) {
GPSTracker.mLastestLocation = new LatLng(location.getLatitude(), location.getLongitude());
adapter.notifyDataSetChanged();
}
}
}
示例14: run
import com.google.android.gms.location.LocationResult; //导入依赖的package包/类
@SuppressLint("MissingPermission")
@Override
protected Task<Void> run(ObservableTaskCallback<LocationResult> callback) {
ResultCallback resultCallback = new ResultCallback(callback);
callback.setDisposeListener(() -> client.removeLocationUpdates(resultCallback));
return client.requestLocationUpdates(this.request, resultCallback, null);
}
示例15: createLocationCallback
import com.google.android.gms.location.LocationResult; //导入依赖的package包/类
private LocationCallback createLocationCallback() {
return new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
Log.v(TAG, "Received location result with " + locationResult.getLocations().size() + " locations");
onLocationUpdateReceived(locationResult.getLastLocation());
}
};
}