Search in sources :

Example 1 with GeoFire

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

the class SFVehiclesActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sfvehicles);
    // setup map and camera position
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    this.map = mapFragment.getMap();
    LatLng latLngCenter = new LatLng(INITIAL_CENTER.latitude, INITIAL_CENTER.longitude);
    this.searchCircle = this.map.addCircle(new CircleOptions().center(latLngCenter).radius(1000));
    this.searchCircle.setFillColor(Color.argb(66, 255, 0, 255));
    this.searchCircle.setStrokeColor(Color.argb(66, 0, 0, 0));
    this.map.moveCamera(CameraUpdateFactory.newLatLngZoom(latLngCenter, INITIAL_ZOOM_LEVEL));
    this.map.setOnCameraChangeListener(this);
    FirebaseOptions options = new FirebaseOptions.Builder().setApplicationId("geofire").setDatabaseUrl(GEO_FIRE_DB).build();
    FirebaseApp app = FirebaseApp.initializeApp(this, options);
    // setup GeoFire
    this.geoFire = new GeoFire(FirebaseDatabase.getInstance(app).getReferenceFromUrl(GEO_FIRE_REF));
    // radius in km
    this.geoQuery = this.geoFire.queryAtLocation(INITIAL_CENTER, 1);
    // setup markers
    this.markers = new HashMap<String, Marker>();
}
Also used : SupportMapFragment(com.google.android.gms.maps.SupportMapFragment) GeoFire(com.firebase.geofire.GeoFire) FirebaseOptions(com.google.firebase.FirebaseOptions) FirebaseApp(com.google.firebase.FirebaseApp)

Example 2 with GeoFire

use of com.firebase.geofire.GeoFire 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

GeoFire (com.firebase.geofire.GeoFire)2 GeoLocation (com.firebase.geofire.GeoLocation)1 SupportMapFragment (com.google.android.gms.maps.SupportMapFragment)1 FirebaseApp (com.google.firebase.FirebaseApp)1 FirebaseOptions (com.google.firebase.FirebaseOptions)1 DatabaseError (com.google.firebase.database.DatabaseError)1 TimeoutException (java.util.concurrent.TimeoutException)1