diff options
author | Brad Leege <bleege@gmail.com> | 2015-12-08 14:00:38 -0800 |
---|---|---|
committer | Brad Leege <bleege@gmail.com> | 2015-12-09 12:45:35 -0800 |
commit | cddedf6966051f3ace409bdebbbdac8dc279466f (patch) | |
tree | 7c4948539092bbade93ad8d5ffb8454b720c434b /android | |
parent | a7307f01bbcfeccebf21c8765ffad2348ed8c646 (diff) | |
download | qtlocation-mapboxgl-cddedf6966051f3ace409bdebbbdac8dc279466f.tar.gz |
[android] #2954 - Setting up specific toggle GPS functionality
Diffstat (limited to 'android')
-rw-r--r-- | android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationServices.java | 63 |
1 files changed, 58 insertions, 5 deletions
diff --git a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationServices.java b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationServices.java index 6209874b6b..c3cf8161cf 100644 --- a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationServices.java +++ b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationServices.java @@ -1,17 +1,20 @@ package com.mapbox.mapboxsdk.location; import android.content.Context; +import android.location.Location; import android.support.annotation.NonNull; +import com.mapzen.android.lost.api.LocationListener; import com.mapzen.android.lost.api.LocationRequest; import com.mapzen.android.lost.api.LostApiClient; -public class LocationServices { +public class LocationServices implements LocationListener { private static LocationServices instance = null; private LostApiClient mLocationClient; private LocationRequest mLocationRequest; + private Location lastLocation = null; /** * Private constructor for singleton LocationServices @@ -20,10 +23,6 @@ public class LocationServices { super(); // Setup location services mLocationClient = new LostApiClient.Builder(context).build(); - mLocationRequest = LocationRequest.create() - .setFastestInterval(1000) - .setSmallestDisplacement(3.0f) - .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); } /** @@ -40,4 +39,58 @@ public class LocationServices { } return instance; } + + /** + * Enabled / Disable GPS focused location tracking + * + * @param enableGPS true if GPS is to be enabled, false if GPS is to be disabled + */ + public void toggleGPS(boolean enableGPS) { + + if (enableGPS) { + + if (mLocationClient.isConnected()) { + // Disconnect first to ensure that the new requests are GPS + com.mapzen.android.lost.api.LocationServices.FusedLocationApi.removeLocationUpdates(this); + mLocationClient.disconnect(); + } + + // Setup Fresh + mLocationClient.connect(); + Location lastLocation = com.mapzen.android.lost.api.LocationServices.FusedLocationApi.getLastLocation(); + if (lastLocation != null) { + this.lastLocation = lastLocation; + } + + // LocationRequest Tuned for GPS + mLocationRequest = LocationRequest.create() + .setFastestInterval(1000) + .setSmallestDisplacement(3.0f) + .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); + + com.mapzen.android.lost.api.LocationServices.FusedLocationApi.requestLocationUpdates(mLocationRequest, this); + + + } else { + + // Disconnect + if (mLocationClient.isConnected()) { + // Disconnect first to ensure that the new requests are GPS + com.mapzen.android.lost.api.LocationServices.FusedLocationApi.removeLocationUpdates(this); + mLocationClient.disconnect(); + } + + } + + + } + + @Override + public void onLocationChanged(Location location) { + this.lastLocation = location; + } + + public Location getLastLocation() { + return lastLocation; + } } |