Class Veery

requestRouteMatch(RouteMatch callback)

Request Veery to be warned when a new trip was computed by the backend.

This could be used to refresh a Maps activity.

Parameters

Param name Type Usage
callback RouteMatch Callback that will be triggered

Returns

void

Usage / Example

Inline pattern

 veery.requestRouteMatch(new Veery.RouteMatch() {
    @Override
    public void onRouteMatch(Veery.Locations locations) {
         //
         // do whatever you need with the Location object
         //
    }
 });

Interface on activity pattern

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

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

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

    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.BACKEND);
  // Requires Android Veery 1.3.2
  //veery.activate(Veery.BACKGROUND_GEOLOC  | Veery.ROUTE_MATCH );

        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.requestRouteMatch(this);
    }

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

    @Override
    protected void onDestroy() {
        super.onDestroy();
        try {
            veery.stopRouteMatch();
            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 onRouteMatch(Veery.Locations locations) {
        if (mMap!=null) {
            mMap.clear();
            final JSONObject[] geoJsonData = locations.toGeoJSONArray();

            if (geoJsonData != null) {
                for (int i = 0; i<geoJsonData.length;i++) {
                    JSONObject object = geoJsonData[i];
                    GeoJsonLayer layer = new GeoJsonLayer(mMap, object);
                    layer.addLayerToMap();
                }
            }
        }
    }
}

Info

GeoJsonLayer classes are available on Google Maps API

User interaction

none

See also

getLocationHistory

Get the historical geolocation data for the mentioned period.

countLocationHistory

Count Historical data of Geolocations observed during a given period of time.

requestRouteMatch

Request for a callback event when a new trip is routematched by the Veery Backend.

stopRouteMatch

Cancel the call to requestRouteMatch.

Locations.toArray

Return an array of Location object.

Locations.toGeoJSON

Return a GeoJSON containing the set of locations (Point or MultiLineString).

Locations.toGeoJSONArray

Return an array of GeoJSON.

Locations.getBoundingBox

Get the bounding box which envelopes all locations in the set.

RouteMatch.onRouteMatch

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