Search in sources :

Example 1 with GeoLocation

use of com.firebase.geofire.GeoLocation in project geofire-java by firebase.

the class SFVehiclesActivity method onCameraChange.

@Override
public void onCameraChange(CameraPosition cameraPosition) {
    // Update the search criteria for this geoQuery and the circle on the map
    LatLng center = cameraPosition.target;
    double radius = zoomLevelToRadius(cameraPosition.zoom);
    this.searchCircle.setCenter(center);
    this.searchCircle.setRadius(radius);
    this.geoQuery.setCenter(new GeoLocation(center.latitude, center.longitude));
    // radius in km
    this.geoQuery.setRadius(radius / 1000);
}
Also used : GeoLocation(com.firebase.geofire.GeoLocation)

Example 2 with GeoLocation

use of com.firebase.geofire.GeoLocation in project geofire-java by firebase.

the class GeoFireTestingRule method setLocation.

/**
 * Sets a given location key from the latitude and longitude on the provided Geofire instance.
 * This operation will run asychronously or synchronously depending on the wait boolean.
 */
public void setLocation(GeoFire geoFire, String key, double latitude, double longitude, boolean wait) {
    final SimpleFuture<DatabaseError> futureError = new SimpleFuture<DatabaseError>();
    geoFire.setLocation(key, new GeoLocation(latitude, longitude), new GeoFire.CompletionListener() {

        @Override
        public void onComplete(String key, DatabaseError error) {
            futureError.put(error);
        }
    });
    if (wait) {
        try {
            assertNull(futureError.get(timeout, TimeUnit.SECONDS));
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (TimeoutException e) {
            fail("Timeout occured!");
        }
    }
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) GeoFire(com.firebase.geofire.GeoFire) GeoLocation(com.firebase.geofire.GeoLocation) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

GeoLocation (com.firebase.geofire.GeoLocation)2 GeoFire (com.firebase.geofire.GeoFire)1 DatabaseError (com.google.firebase.database.DatabaseError)1 TimeoutException (java.util.concurrent.TimeoutException)1