Interface Veery.PredictionUpdate

onPredictionUpdate(Veery.Predictions predictions)

Interface Callback triggered when the backend computed a new prediction.

Parameters

Param name Type Usage
predictions Veery.Predictions object a Predictions object

Returns

void

Usage / Example

Inline pattern

 veery.requestPredictionUpdate(new Veery.PredictionUpdate() {
    @Override
    public void onPredictionUpdate(Predictions predictions) {
         //
         // do whatever you need with the Prediction object
         //
    }
 });

Interface on activity pattern

The following example implement a Google Maps activity and update it when a POIs update happens

import android.location.Location;                                   
import com.roofstreet.android.veery.*;

public class MapsActivity extends AppCompatActivity implements
                    OnMapReadyCallback,
                    Veery.PredictionUpdate {

    private final Veery veery = new Veery(this);
    private GoogleMap mMap = null;

    protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          veery.serviceConnect();
          veery.setApiKeySecret("SuPeRScrET12345789GhJ");
          FirebaseApp.initializeApp(this);
          veery.setFirebaseToken(FirebaseInstanceId.getInstance().getToken());


          //
          veery.activate(Veery.GEOPROFILE); // required for Predictions
          // Requires Android Veery 1.3.2
          //veery.activate(Veery.BACKGROUND_GEOLOC  | Veery.PREDICTION );
          setContentView(R.layout.activity_maps);

          // Added by Google Maps
          // Obtain the SupportMapFragment and get notified when the map is ready to be used.
          SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                                          .findFragmentById(R.id.map);
          mapFragment.getMapAsync(this);
        }

    @Override
    protected void onResume() {
          super.onResume();
          veery.serviceResume();
          veery.requestPredictionUpdate(this);
      }

    @Override
    protected void onPause() {
            super.onPause();
            veery.servicePause();
          }

    @Override
    protected void onDestroy() {
          super.onDestroy();
          try {
                veery.stopPredictionUpdate();
                veery.serviceDisconnect();
              } catch (Throwable t) {
              }
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
            mMap = googleMap;
            mMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
                    @Override
                    public void onMapLoaded() {
                            mMap.setPadding(200, 100, 0, 200);
                    }
                  });
            }

    @Override
    public void onPredictionUpdate(Predictions predictions) {
            if (mMap!=null) {
                mMap.clear();

              JSONObject geoJsonData = predictions.toGeojson();

            if (geoJsonData!= null){
                                 GeoJsonLayer layer = new GeoJsonLayer(mMap, geoJsonData);
                                 layer.addLayerToMap();
                }                               
              }
            }
    }

Info

GeoJsonLayer classes are available on Google Maps API

User interaction

none

See also

getNextTrip

Get the next estimated trip for that user.

requestPredictionUpdate

Request for a callback event when a new prediction is computed by the Veery Backend.

stopPredictionUpdate

Cancel the call to requestPredictionUpdate.

Predictions.isOK

Return true if a prediction is in the Cache.

Predictions.isOutdated

Return true if the prediction is outdated (made previously, but now concerns a time in the past)

Predictions.getProbability

Get the level of certainty of the predictive algorithm.

Predictions.getDestinationLongitude getDestinationLatitude

Get the coordinates of the next predicted destination

Predictions.getTrip toGeojson

Get the next predicted trip in GeoJSON format.

Predictions.toLocations

Get the next trip in the form of a Location array.

Predictions.getStartTrip

Get the next start point of the prediction.

Predictions.getStartTime

Get the estimated start time predicted for the next trip.

Predictions.getStartName

Get the name (street name) of the predicted departure place.

Predictions.getArrivalTime

Get the estimated arrival time predicted for the next trip.

Predictions.getArrivalTimeUTC

Get the estimated arrival time predicted for the next trip (returns EPOCH).

Predictions.getArrivalName

Get the name (street name) of the predicted arrival place.

PredictionUpdate.onPredictionUpdate

Callback triggered every time a new prediction is computed by the Veery backend.