use of com.google.android.gms.location.LocationCallback in project android-play-location by googlesamples.
the class LocationUpdatesService method onCreate.
@Override
public void onCreate() {
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
mLocationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
super.onLocationResult(locationResult);
onNewLocation(locationResult.getLastLocation());
}
};
createLocationRequest();
getLastLocation();
HandlerThread handlerThread = new HandlerThread(TAG);
handlerThread.start();
mServiceHandler = new Handler(handlerThread.getLooper());
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Android O requires a Notification Channel.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = getString(R.string.app_name);
// Create the channel for the notification
NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, NotificationManager.IMPORTANCE_DEFAULT);
// Set the Notification Channel for the Notification Manager.
mNotificationManager.createNotificationChannel(mChannel);
}
}
use of com.google.android.gms.location.LocationCallback in project Walrus by megabug.
the class ProjectWalrusApplication method startLocationUpdates.
public static void startLocationUpdates() {
FusedLocationProviderClient fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(context);
LocationRequest locationRequest = LocationRequest.create();
locationRequest.setInterval(2000);
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
try {
fusedLocationProviderClient.requestLocationUpdates(locationRequest, new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
for (Location location : locationResult.getLocations()) {
if (currentBestLocation == null || GeoUtils.isBetterLocation(location, currentBestLocation))
currentBestLocation = location;
}
}
}, null);
} catch (SecurityException ignored) {
}
}
use of com.google.android.gms.location.LocationCallback in project GogoNew by kuldeep725.
the class MapsActivity method onLocationChanged.
@Override
public void onLocationChanged(Location location) {
Log.e(TAG, "Firing onLocationChanged..............................................");
mLocationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
for (Location location : locationResult.getLocations()) {
// Update UI with location data
// ...
mCurrentLocation = location;
Log.e(TAG, "@onLocationChanged--> mCurrentLocation");
}
}
};
}
use of com.google.android.gms.location.LocationCallback in project TrekAdvisor by peterLaurence.
the class MapViewFragment method onAttach.
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof RequestManageTracksListener && context instanceof RequestManageMarkerListener && context instanceof MapProvider) {
mRequestManageTracksListener = (RequestManageTracksListener) context;
mRequestManageMarkerListener = (RequestManageMarkerListener) context;
mMapProvider = (MapProvider) context;
} else {
throw new RuntimeException(context.toString() + " must implement RequestManageTracksListener, MapProvider and LocationProvider");
}
/* The Google api client is re-created here as the onAttach method will always be called for
* a retained fragment.
*/
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this.getActivity().getApplicationContext());
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(1000);
mLocationRequest.setFastestInterval(1000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
for (Location location : locationResult.getLocations()) {
onLocationReceived(location);
}
}
};
}
use of com.google.android.gms.location.LocationCallback in project TrekAdvisor by peterLaurence.
the class LocationService method onCreate.
@Override
public void onCreate() {
EventBus.getDefault().register(this);
/* Start up the thread running the service. Note that we create a separate thread because
* the service normally runs in the process's main thread, which we don't want to block.
* We also make it background priority so CPU-intensive work will not disrupt our UI.
*/
HandlerThread thread = new HandlerThread("LocationServiceThread", Thread.MIN_PRIORITY);
thread.start();
/* Get the HandlerThread's Looper and use it for our Handler */
mServiceLooper = thread.getLooper();
mServiceHandler = new Handler(mServiceLooper);
mServiceHandler.handleMessage(new Message());
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this.getApplicationContext());
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(1000);
mLocationRequest.setFastestInterval(1000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
/* Create the Gpx instance */
mTrackPoints = new ArrayList<>();
mLocationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
for (Location location : locationResult.getLocations()) {
mServiceHandler.post(() -> {
TrackPoint.Builder pointBuilder = new TrackPoint.Builder();
pointBuilder.setLatitude(location.getLatitude());
pointBuilder.setLongitude(location.getLongitude());
pointBuilder.setElevation(location.getAltitude());
TrackPoint trackPoint = pointBuilder.build();
mTrackPoints.add(trackPoint);
});
}
}
};
startLocationUpdates();
}
Aggregations