Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose list of key points leading up to the enhanced location update #2452

Merged
merged 11 commits into from
Feb 12, 2020
4 changes: 2 additions & 2 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ License: [The Apache Software License, Version 2.0](http://www.apache.org/licens

Mapbox Navigation uses portions of the Mapbox Android Core Library.
URL: [https://github.com/mapbox/mapbox-events-android](https://github.com/mapbox/mapbox-events-android)
License: [The Apache Software License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt)
License: [The MIT License](https://opensource.org/licenses/MIT)

===========================================================================

Expand All @@ -570,7 +570,7 @@ License: [BSD](https://opensource.org/licenses/BSD-2-Clause)

Mapbox Navigation uses portions of the Mapbox Android Telemetry Library.
URL: [https://github.com/mapbox/mapbox-events-android](https://github.com/mapbox/mapbox-events-android)
License: [The Apache Software License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt)
License: [The MIT License](https://opensource.org/licenses/MIT)

===========================================================================

Expand Down
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ allprojects {
mavenCentral()
jcenter()
maven { url 'https://plugins.gradle.org/m2' }
maven {
url 'https://mapbox.bintray.com/mapbox_private'
credentials {
username = project.hasProperty('BINTRAY_USER') ? project.property('BINTRAY_USER') : System.getenv('BINTRAY_USER')
password = project.hasProperty('BINTRAY_API_KEY') ? project.property('BINTRAY_API_KEY') : System.getenv('BINTRAY_API_KEY')
}
}
maven { url 'https://mapbox.bintray.com/mapbox' }
maven { url 'https://oss.jfrog.org/artifactory/oss-snapshot-local/' }
}
Expand Down
8 changes: 0 additions & 8 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,6 @@ jobs:
# - run:
# name: Check public documentation
# command: sh scripts/dokka-validate.sh
- run:
name: Generate Bintray credentials
command: |
if [ -n "${BINTRAY_USER}" ]; then
echo "BINTRAY_USER=$BINTRAY_USER
BINTRAY_API_KEY=$BINTRAY_API_KEY
GPG_PASSPHRASE=$GPG_PASSPHRASE"
fi
- deploy:
name: Publish Navigation SDK 1.0 to Bintray
command: |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mapbox.navigation.examples.activity

import android.annotation.SuppressLint
import android.location.Location
import android.os.Bundle
import android.os.Looper
import android.view.View.GONE
Expand Down Expand Up @@ -31,7 +32,9 @@ import com.mapbox.navigation.base.trip.model.RouteProgress
import com.mapbox.navigation.core.MapboxNavigation
import com.mapbox.navigation.core.directions.session.RoutesObserver
import com.mapbox.navigation.core.directions.session.RoutesRequestCallback
import com.mapbox.navigation.core.trip.session.LocationObserver
import com.mapbox.navigation.core.trip.session.RouteProgressObserver
import com.mapbox.navigation.core.trip.session.TripSessionStateObserver
import com.mapbox.navigation.examples.R
import com.mapbox.navigation.examples.utils.Utils
import com.mapbox.navigation.examples.utils.extensions.toPoint
Expand Down Expand Up @@ -59,9 +62,7 @@ class SimpleMapboxNavigationKt : AppCompatActivity(), OnMapReadyCallback {
mapView.getMapAsync(this)
localLocationEngine = LocationEngineProvider.getBestLocationEngine(applicationContext)
mapboxNavigation = MapboxNavigation(applicationContext, Utils.getMapboxAccessToken(this))
startLocationUpdates()
startNavigation.setOnClickListener {
stopLocationUpdates()
mapboxNavigation.startTripSession()
}
}
Expand Down Expand Up @@ -116,6 +117,25 @@ class SimpleMapboxNavigationKt : AppCompatActivity(), OnMapReadyCallback {
}
}

private val locationObserver = object : LocationObserver {
override fun onRawLocationChanged(rawLocation: Location) {
Timber.d("raw location %s", rawLocation.toString())
}

override fun onEnhancedLocationChanged(
enhancedLocation: Location,
keyPoints: List<Location>
) {
if (keyPoints.isNotEmpty()) {
locationComponent?.forceLocationUpdate(keyPoints, true)
} else {
locationComponent?.forceLocationUpdate(enhancedLocation)
}
Timber.d("enhanced location %s", enhancedLocation)
Timber.d("enhanced keyPoints %s", keyPoints)
}
}

private fun startLocationUpdates() {
val request = LocationEngineRequest.Builder(1000L)
.setFastestInterval(500L)
Expand Down Expand Up @@ -150,7 +170,7 @@ class SimpleMapboxNavigationKt : AppCompatActivity(), OnMapReadyCallback {

private val routeProgressObserver = object : RouteProgressObserver {
override fun onRouteProgressChanged(routeProgress: RouteProgress) {
Timber.e("route progress %s", routeProgress.toString())
Timber.d("route progress %s", routeProgress.toString())
}
}

Expand All @@ -161,28 +181,37 @@ class SimpleMapboxNavigationKt : AppCompatActivity(), OnMapReadyCallback {
Toast.makeText(this@SimpleMapboxNavigationKt, "Empty routes", Toast.LENGTH_SHORT)
.show()
}
Timber.e("route changed %s", routes.toString())
Timber.d("route changed %s", routes.toString())
}
}

private val routesReqCallback = object : RoutesRequestCallback {
override fun onRoutesReady(routes: List<DirectionsRoute>): List<DirectionsRoute> {
Timber.e("route request success %s", routes.toString())
startNavigation.visibility = VISIBLE
Timber.d("route request success %s", routes.toString())
return routes
}

override fun onRoutesRequestFailure(throwable: Throwable, routeOptions: RouteOptions) {
symbolManager?.deleteAll()
Timber.e("route request failure %s", throwable.toString())
startNavigation.visibility = GONE
}

override fun onRoutesRequestCanceled(routeOptions: RouteOptions) {
symbolManager?.deleteAll()
Timber.e("route request canceled")
Timber.d("route request canceled")
}
}

private val tripSessionStateObserver = object : TripSessionStateObserver {
override fun onSessionStarted() {
stopLocationUpdates()
startNavigation.visibility = GONE
}

override fun onSessionStopped() {
startLocationUpdates()
startNavigation.visibility = VISIBLE
}
}

public override fun onResume() {
Expand All @@ -198,15 +227,20 @@ class SimpleMapboxNavigationKt : AppCompatActivity(), OnMapReadyCallback {
override fun onStart() {
super.onStart()
mapView.onStart()
mapboxNavigation.registerLocationObserver(locationObserver)
mapboxNavigation.registerRouteProgressObserver(routeProgressObserver)
mapboxNavigation.registerRoutesObserver(routesObserver)
mapboxNavigation.registerTripSessionStateObserver(tripSessionStateObserver)
}

override fun onStop() {
super.onStop()
mapView.onStop()
mapboxNavigation.unregisterLocationObserver(locationObserver)
mapboxNavigation.unregisterRouteProgressObserver(routeProgressObserver)
mapboxNavigation.unregisterRoutesObserver(routesObserver)
mapboxNavigation.unregisterTripSessionStateObserver(tripSessionStateObserver)
stopLocationUpdates()
}

override fun onLowMemory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ class TripSessionActivityKt : AppCompatActivity(), OnMapReadyCallback {
mapboxMap?.locationComponent?.forceLocationUpdate(rawLocation)
}

override fun onEnhancedLocationChanged(enhancedLocation: Location) {
override fun onEnhancedLocationChanged(
enhancedLocation: Location,
keyPoints: List<Location>
) {
Timber.d("DEBUG enhanced location: $enhancedLocation")
Timber.d("DEBUG enhanced keyPoints: $keyPoints")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@
app:layout_constraintBottom_toBottomOf="parent"
android:background="@color/colorPrimary"
android:text="@string/start_navigation"
android:textColor="@android:color/white"
android:visibility="gone" />
android:textColor="@android:color/white" />
</androidx.constraintlayout.widget.ConstraintLayout>
4 changes: 2 additions & 2 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ ext {
]

version = [
mapboxMapSdk : '8.6.2',
mapboxMapSdk : '9.1.0-SNAPSHOT',
mapboxSdkServices : '5.1.0-beta.1',
mapboxSdkDirectionsModels : '5.1.0-beta.1',
mapboxEvents : '4.5.1',
mapboxCore : '1.3.0',
mapboxNavigator : '9.0.4',
mapboxNavigator : 'ms-bearing-from-shape-on-interpolation-SNAPSHOT-2',
mapboxCrashMonitor : '2.0.0',
mapboxAnnotationPlugin : '0.7.0',
mapboxAccounts : '0.3.1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import com.mapbox.navigator.HttpInterface
import com.mapbox.navigator.HttpResponse
import com.mapbox.services.android.navigation.BuildConfig
import java.io.ByteArrayOutputStream
import java.lang.IllegalArgumentException
import java.io.IOException
import okhttp3.Call
import okhttp3.Callback
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import okhttp3.logging.HttpLoggingInterceptor
import okio.Okio
import timber.log.Timber
Expand All @@ -29,11 +32,9 @@ internal class HttpClient(

private val client: OkHttpClient by lazy {
if (BuildConfig.DEBUG) {
val interceptor = HttpLoggingInterceptor(object : HttpLoggingInterceptor.Logger {
override fun log(message: String) {
Timber.d(message)
}
}).setLevel(HttpLoggingInterceptor.Level.BASIC)
val interceptor = HttpLoggingInterceptor(
HttpLoggingInterceptor.Logger { message -> Timber.d(message) }
).setLevel(HttpLoggingInterceptor.Level.BASIC)

clientBuilder.addInterceptor(interceptor)
}
Expand All @@ -51,33 +52,40 @@ internal class HttpClient(
return acceptGzipEncoding
}

override fun get(url: String): HttpResponse {
override fun get(url: String, nativeResponse: HttpResponse) {
val requestBuilder = try {
Request.Builder()
.addHeader(HEADER_USER_AGENT, userAgent)
.url(url)
} catch (e: IllegalArgumentException) {
return HttpResponse(ByteArray(0), HttpCode.FAILURE)
nativeResponse.run(ByteArray(0), HttpCode.FAILURE)
return
}

if (acceptGzipEncoding) {
requestBuilder.addHeader(HEADER_ENCODING, GZIP)
}

client.newCall(requestBuilder.build()).execute().use { response ->
val outputStream = ByteArrayOutputStream()
val result = if (response.isSuccessful) HttpCode.SUCCESS else HttpCode.FAILURE

response.body()?.let { body ->
val sink = Okio.buffer(Okio.sink(outputStream))
sink.writeAll(body.source())
sink.close()
client.newCall(requestBuilder.build()).enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
nativeResponse.run(ByteArray(0), HttpCode.FAILURE)
}

val bytes = outputStream.toByteArray()
outputStream.close()
override fun onResponse(call: Call, response: Response) {
val outputStream = ByteArrayOutputStream()
val result = if (response.isSuccessful) HttpCode.SUCCESS else HttpCode.FAILURE

return HttpResponse(bytes, result)
}
response.body()?.let { body ->
val sink = Okio.buffer(Okio.sink(outputStream))
sink.writeAll(body.source())
sink.close()
}

val bytes = outputStream.toByteArray()
outputStream.close()

nativeResponse.run(bytes, result)
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,13 @@ enum class RouteProgressState {
* A lack of [android.location.Location] updates from the phone has caused lack of confidence in the
* progress updates being sent.
*/
LOCATION_STALE
LOCATION_STALE,

/**
* State when we start following a route.
*
* After a certain number of tracking points we gain confidence and switch to tracking state.
* We do map-matching rather than route line snapping during this state.
*/
ROUTE_UNCERTAIN
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class RouteProgressStateMap : HashMap<RouteState, RouteProgressState?>() {
put(RouteState.COMPLETE, RouteProgressState.ROUTE_ARRIVED)
put(RouteState.TRACKING, RouteProgressState.LOCATION_TRACKING)
put(RouteState.STALE, RouteProgressState.LOCATION_STALE)
put(RouteState.UNCERTAIN, RouteProgressState.ROUTE_UNCERTAIN)
put(RouteState.OFFROUTE, null) // Ignore off-route (info already provided via listener)
}
}
Loading