Search in sources :

Example 1 with LocationCallback

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);
    }
}
Also used : NotificationChannel(android.app.NotificationChannel) HandlerThread(android.os.HandlerThread) LocationCallback(com.google.android.gms.location.LocationCallback) Handler(android.os.Handler) LocationResult(com.google.android.gms.location.LocationResult)

Example 2 with LocationCallback

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) {
    }
}
Also used : LocationRequest(com.google.android.gms.location.LocationRequest) LocationCallback(com.google.android.gms.location.LocationCallback) FusedLocationProviderClient(com.google.android.gms.location.FusedLocationProviderClient) LocationResult(com.google.android.gms.location.LocationResult) Location(android.location.Location)

Example 3 with LocationCallback

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");
            }
        }
    };
}
Also used : LocationCallback(com.google.android.gms.location.LocationCallback) LocationResult(com.google.android.gms.location.LocationResult) Location(android.location.Location)

Example 4 with LocationCallback

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);
            }
        }
    };
}
Also used : MapProvider(com.peterlaurence.trekadvisor.menu.MapProvider) LocationRequest(com.google.android.gms.location.LocationRequest) LocationCallback(com.google.android.gms.location.LocationCallback) LocationResult(com.google.android.gms.location.LocationResult) Location(android.location.Location)

Example 5 with LocationCallback

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();
}
Also used : HandlerThread(android.os.HandlerThread) Message(android.os.Message) LocationRequest(com.google.android.gms.location.LocationRequest) LocationCallback(com.google.android.gms.location.LocationCallback) Handler(android.os.Handler) TrackPoint(com.peterlaurence.trekadvisor.util.gpx.model.TrackPoint) LocationResult(com.google.android.gms.location.LocationResult) Location(android.location.Location)

Aggregations

LocationCallback (com.google.android.gms.location.LocationCallback)9 LocationResult (com.google.android.gms.location.LocationResult)9 Location (android.location.Location)8 Intent (android.content.Intent)3 Handler (android.os.Handler)3 LocationRequest (com.google.android.gms.location.LocationRequest)3 HandlerThread (android.os.HandlerThread)2 GoogleApiClient (com.google.android.gms.common.api.GoogleApiClient)2 SupportMapFragment (com.google.android.gms.maps.SupportMapFragment)2 SuppressLint (android.annotation.SuppressLint)1 NotificationChannel (android.app.NotificationChannel)1 ProgressDialog (android.app.ProgressDialog)1 Message (android.os.Message)1 NonNull (android.support.annotation.NonNull)1 NavigationView (android.support.design.widget.NavigationView)1 DrawerLayout (android.support.v4.widget.DrawerLayout)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 AppCompatImageButton (android.support.v7.widget.AppCompatImageButton)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1