Search in sources :

Example 1 with LocationResult

use of com.google.android.gms.location.LocationResult in project android-play-location by googlesamples.

the class LocationUpdatesBroadcastReceiver method onReceive.

@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();
                Utils.setLocationUpdatesResult(context, locations);
                Utils.sendNotification(context, Utils.getLocationResultTitle(context, locations));
                Log.i(TAG, Utils.getLocationUpdatesResult(context));
            }
        }
    }
}
Also used : LocationResult(com.google.android.gms.location.LocationResult) Location(android.location.Location)

Example 2 with LocationResult

use of com.google.android.gms.location.LocationResult 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 3 with LocationResult

use of com.google.android.gms.location.LocationResult 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 4 with LocationResult

use of com.google.android.gms.location.LocationResult 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 5 with LocationResult

use of com.google.android.gms.location.LocationResult 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)

Aggregations

LocationResult (com.google.android.gms.location.LocationResult)11 Location (android.location.Location)10 LocationCallback (com.google.android.gms.location.LocationCallback)9 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