diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationServices.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationServices.java
index ac2ab6407..f59921cee 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationServices.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationServices.java
@@ -1,8 +1,12 @@
package com.mapbox.mapboxsdk.location;
import android.content.Context;
+import android.content.Intent;
import android.location.Location;
+import android.location.LocationManager;
import android.support.annotation.NonNull;
+import android.util.Log;
+import com.mapbox.mapboxsdk.telemetry.TelemetryLocationReceiver;
import com.mapzen.android.lost.api.LocationRequest;
import com.mapzen.android.lost.api.LostApiClient;
import java.util.ArrayList;
@@ -10,8 +14,11 @@ import java.util.List;
public class LocationServices implements com.mapzen.android.lost.api.LocationListener {
+ private static final String TAG = "LocationServices";
+
private static LocationServices instance = null;
+ private Context context;
private LostApiClient mLocationClient;
private LocationRequest mLocationRequest;
@@ -26,6 +33,7 @@ public class LocationServices implements com.mapzen.android.lost.api.LocationLis
*/
private LocationServices(Context context) {
super();
+ this.context = context;
// Setup location services
mLocationClient = new LostApiClient.Builder(context).build();
locationListeners = new ArrayList<>();
@@ -53,21 +61,22 @@ public class LocationServices implements com.mapzen.android.lost.api.LocationLis
*/
public void toggleGPS(boolean enableGPS) {
+ // 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();
+ }
+
+ // Setup Fresh
+ mLocationClient.connect();
+ Location lastLocation = com.mapzen.android.lost.api.LocationServices.FusedLocationApi.getLastLocation();
+ if (lastLocation != null) {
+ this.lastLocation = lastLocation;
+ }
+
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)
@@ -78,12 +87,13 @@ public class LocationServices implements com.mapzen.android.lost.api.LocationLis
} 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();
- }
+ // LocationRequest Tuned for PASSIVE
+ mLocationRequest = LocationRequest.create()
+ .setFastestInterval(1000)
+ .setSmallestDisplacement(3.0f)
+ .setPriority(LocationRequest.PRIORITY_NO_POWER);
+
+ com.mapzen.android.lost.api.LocationServices.FusedLocationApi.requestLocationUpdates(mLocationRequest, this);
}
@@ -96,12 +106,18 @@ public class LocationServices implements com.mapzen.android.lost.api.LocationLis
@Override
public void onLocationChanged(Location location) {
+ Log.i(TAG, "onLocationChanged()..." + location);
this.lastLocation = location;
// Update Listeners
for (LocationListener listener : this.locationListeners) {
listener.onLocationChanged(location);
}
+
+ // Update the Telemetry Receiver
+ Intent locIntent = new Intent(TelemetryLocationReceiver.INTENT_STRING);
+ locIntent.putExtra(LocationManager.KEY_LOCATION_CHANGED, location);
+ context.sendBroadcast(locIntent);
}
/**
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
index 2a428947d..5a47c5b3a 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
@@ -79,6 +79,7 @@ import com.mapbox.mapboxsdk.exceptions.TelemetryServiceNotConfiguredException;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.layers.CustomLayer;
+import com.mapbox.mapboxsdk.telemetry.TelemetryService;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import java.lang.annotation.Retention;
@@ -364,14 +365,17 @@ public class MapView extends FrameLayout {
mMapboxMap.setMyLocationTrackingMode(savedInstanceState.getInt(MapboxConstants.STATE_MY_LOCATION_TRACKING_MODE, MyLocationTracking.TRACKING_NONE));
//noinspection ResourceType
mMapboxMap.setMyBearingTrackingMode(savedInstanceState.getInt(MapboxConstants.STATE_MY_BEARING_TRACKING_MODE, MyBearingTracking.NONE));
+ } else {
+ // Force a check for Telemetry
+ validateTelemetryServiceConfigured();
+
+ Intent telemetryService = new Intent(getContext(), TelemetryService.class);
+ getContext().startService(telemetryService);
}
// Force a check for an access token
validateAccessToken(getAccessToken());
- // Force a check for Telemetry
- validateTelemetryServiceConfigured();
-
// Initialize EGL
mNativeMapView.initializeDisplay();
mNativeMapView.initializeContext();
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/TelemetryLocationReceiver.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/TelemetryLocationReceiver.java
index ccac33d5a..96d1a8699 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/TelemetryLocationReceiver.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/TelemetryLocationReceiver.java
@@ -14,6 +14,8 @@ public class TelemetryLocationReceiver extends BroadcastReceiver {
private static final String TAG = "TelemLocationReceiver";
+ public static final String INTENT_STRING = "com.mapbox.mapboxsdk.telemetry.TelemetryLocationReceiver";
+
/**
* Default Constructor
*/
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/TelemetryService.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/TelemetryService.java
index c49eb1aa3..f0ce0e10c 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/TelemetryService.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/TelemetryService.java
@@ -55,7 +55,7 @@ public class TelemetryService extends Service {
super.onCreate();
// Enable Location Listening for lifecycle of app
- IntentFilter filter = new IntentFilter("com.mapbox.mapboxsdk.telemetry.TelemetryLocationReceiver");
+ IntentFilter filter = new IntentFilter(TelemetryLocationReceiver.INTENT_STRING);
telemetryLocationReceiver = new TelemetryLocationReceiver();
registerReceiver(telemetryLocationReceiver, filter);
}
@@ -137,8 +137,10 @@ public class TelemetryService extends Service {
// Start Ambient Location Listening
// TODO
- Intent locIntent = new Intent("com.mapbox.hermes.LocationReceiver");
+/*
+ Intent locIntent = new Intent(TelemetryLocationReceiver.INTENT_STRING);
locationPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 14872, locIntent, PendingIntent.FLAG_CANCEL_CURRENT);
+*/
try {
// Request Location Updates to be delivered to PendingIntent
// Currently Not supported in LOST
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
index c5106a4c7..70c9259fa 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
@@ -5,6 +5,7 @@
+