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>();
}
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!");
}
}
}
Aggregations