本文整理汇总了Java中com.google.android.gms.location.LocationResult.getLastLocation方法的典型用法代码示例。如果您正苦于以下问题:Java LocationResult.getLastLocation方法的具体用法?Java LocationResult.getLastLocation怎么用?Java LocationResult.getLastLocation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.location.LocationResult
的用法示例。
在下文中一共展示了LocationResult.getLastLocation方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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();
}
}
}
}
示例3: 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();
}
};
}
示例4: 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);
}
};
}
示例5: 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);
}
}
};
}
示例6: 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);
}
示例7: 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;
}
示例8: 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();
}
}
}
示例9: onCreate
import com.google.android.gms.location.LocationResult; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
Log.d("LocationService", "onCreate");
manager = new DataProviderManager();
manager.addObserver(this);
mClient = LocationServices.getFusedLocationProviderClient(this);
//implementation of the location update callback
//what happens when the service receives the user location is defined here
callback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
lastLocation = locationResult.getLastLocation();
Log.d("LocationService", "new location received");
notifyUIOfNewPosition();
//update the location providers with the new location
manager.onLocationChanged(lastLocation);
if (PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean(getString(R.string.pref_active_key), getResources().getBoolean(R.bool.pref_active_default))
&& manager.isCameraNearerThan(Float.parseFloat(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString(getString(R.string.pref_radius_key), getString(R.string.pref_radius_default))), lastLocation)) {
enableCameraWarning();
} else {
disableCameraWarning();
}
}
};
//build the notification for @see {@link #startForeground()} to keep the service from being killed
startForeground(CAMERA_FOREGROUND_SERVICE_NOTIFICATION_ID, buildForegroundNotification());
}
示例10: onLocationResult
import com.google.android.gms.location.LocationResult; //导入方法依赖的package包/类
@Override
public void onLocationResult(LocationResult result) {
super.onLocationResult(result);
final Location location = result.getLastLocation();
if (location == null)
return;
//Update the user location icon.
if (userMarker == null) {
final MarkerOptions options = new MarkerOptions()
.position(new LatLng(location.getLatitude(), location.getLongitude()))
.draggable(false)
.flat(true)
.visible(true)
.anchor(0.5f, 0.5f)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.user_location));
getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
userMarker = googleMap.addMarker(options);
}
});
} else {
userMarker.setPosition(new LatLng(location.getLatitude(), location.getLongitude()));
}
if (mPanMode.get() == AutoPanMode.USER) {
Timber.d("User location changed.");
updateCamera(MapUtils.locationToCoord(location), (int) getMap().getCameraPosition().zoom);
}
if (mLocationListener != null) {
mLocationListener.onLocationChanged(location);
}
}
示例11: 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(LocationResult locationResult) {
super.onLocationResult(locationResult);
mLastLocation = locationResult.getLastLocation();
logger.append("\n\n" + DateFormat.getTimeInstance().format(new Date()) + ": ");
logger.append(" Lat: " + String.valueOf(mLastLocation.getLatitude()));
logger.append(" Long: " + String.valueOf(mLastLocation.getLongitude()) + "\n");
startIntentService();
}
};
}
示例12: onConnected
import com.google.android.gms.location.LocationResult; //导入方法依赖的package包/类
@Override
public void onConnected(Bundle connectionHint) {
Log.i("CaptureActivity", "onConnected called");
clientReady = true;
//Use a new thread to request location updates for the worker thread.
//This new thread waits until the result of the request for updates is complete.
Runnable r = new Runnable(){
@Override
public void run() {
LocationRequest request = new LocationRequest();
request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY).setInterval(5000);
LocationCallback locationCallback = new LocationCallback() {
@Override
public void onLocationAvailability(LocationAvailability availability) {
if (!availability.isLocationAvailable()) {
locationReady = false;
}
}
public void onLocationResult(LocationResult result) {
newestLocation = result.getLastLocation();
}
};
PendingResult<Status> requestResult = LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, request, locationCallback, handler.getLooper());
Status requestStatus = requestResult.await();
locationReady = true;
if(requestStatus.isSuccess()) {
locationReady = true;
Log.i("CaptureActivity", "Location update request result success!");
}else {
Log.i("CaptureActivity", "Location update request result: failure!");
}
}
};
new Thread(r).start();
}
示例13: 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(LocationResult locationResult) {
super.onLocationResult(locationResult);
mCurrentLocation = locationResult.getLastLocation();
mLastUpdateTime = DateFormat.getTimeInstance().format(new Date());
updateLocationUI();
}
};
}