com.firebase.geofire.GeoFire Java Examples
The following examples show how to use
com.firebase.geofire.GeoFire.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DriverMapActivity.java From UberClone with MIT License | 6 votes |
private void endRide(){ mRideStatus.setText("picked customer"); erasePolylines(); String userId = FirebaseAuth.getInstance().getCurrentUser().getUid(); DatabaseReference driverRef = FirebaseDatabase.getInstance().getReference().child("Users").child("Drivers").child(userId).child("customerRequest"); driverRef.removeValue(); DatabaseReference ref = FirebaseDatabase.getInstance().getReference("customerRequest"); GeoFire geoFire = new GeoFire(ref); geoFire.removeLocation(customerId); customerId=""; rideDistance = 0; if(pickupMarker != null){ pickupMarker.remove(); } if (assignedCustomerPickupLocationRefListener != null){ assignedCustomerPickupLocationRef.removeEventListener(assignedCustomerPickupLocationRefListener); } mCustomerInfo.setVisibility(View.GONE); mCustomerName.setText(""); mCustomerPhone.setText(""); mCustomerDestination.setText("Destination: --"); mCustomerProfileImage.setImageResource(R.mipmap.ic_default_user); }
Example #2
Source File: GeoFireTestingRule.java From geofire-java with MIT License | 6 votes |
/** This lets you blockingly wait until the onGeoFireReady was fired on the provided Geofire instance. */ public void waitForGeoFireReady(GeoFire geoFire) throws InterruptedException { final Semaphore semaphore = new Semaphore(0); geoFire.getDatabaseReference().addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { semaphore.release(); } @Override public void onCancelled(DatabaseError databaseError) { fail("Firebase error: " + databaseError); } }); assertTrue("Timeout occured!", semaphore.tryAcquire(timeout, TimeUnit.SECONDS)); }
Example #3
Source File: Home.java From UberClone with MIT License | 6 votes |
private void requestPickup(String uid) { DatabaseReference dbRequest=FirebaseDatabase.getInstance().getReference(Common.pickup_request_tbl); GeoFire mGeofire=new GeoFire(dbRequest); mGeofire.setLocation(uid, new GeoLocation(Common.currenLocation.latitude, Common.currenLocation.longitude), new GeoFire.CompletionListener() { @Override public void onComplete(String key, DatabaseError error) { } }); if (riderMarket.isVisible())riderMarket.remove(); riderMarket=mMap.addMarker(new MarkerOptions().title(getResources().getString(R.string.pickup_here)).snippet("").position(new LatLng(Common.currenLocation.latitude, Common.currenLocation.longitude)) .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED))); riderMarket.showInfoWindow(); btnRequestPickup.setText(getResources().getString(R.string.getting_uber)); findDriver(); }
Example #4
Source File: DriverTracking.java From UberClone with MIT License | 6 votes |
private void displayLocation(){ //add driver location if(driverMarker!=null)driverMarker.remove(); driverMarker=mMap.addMarker(new MarkerOptions().position(new LatLng(Common.currentLat, Common.currentLng)) .title("You").icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_marker))); mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(Common.currentLat, Common.currentLng), 14f)); geoFire.setLocation(Common.userID, new GeoLocation(Common.currentLat, Common.currentLng), new GeoFire.CompletionListener() { @Override public void onComplete(String key, DatabaseError error) { } }); //remove route if(direction!=null)direction.remove(); getDirection(); }
Example #5
Source File: DriverHome.java From UberClone with MIT License | 6 votes |
private void displayLocation(){ if (Common.currentLat!=null && Common.currentLng!=null){ if (locationSwitch.isChecked()) { geoFire.setLocation(Common.userID, new GeoLocation(Common.currentLat, Common.currentLng), new GeoFire.CompletionListener() { @Override public void onComplete(String key, DatabaseError error) { LatLng currentLocation = new LatLng(Common.currentLat, Common.currentLng); if (currentLocationMarket != null) currentLocationMarket.remove(); currentLocationMarket = mMap.addMarker(new MarkerOptions().position(currentLocation) .icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_marker)) .title("Your Location")); mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(Common.currentLat, Common.currentLng), 15.0f)); } }); } }else{ Message.messageError(this, Errors.WITHOUT_LOCATION); } }
Example #6
Source File: DriverHome.java From UberClone with MIT License | 6 votes |
private void setUpLocation() { if(ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION)!= PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION)!= PackageManager.PERMISSION_GRANTED){ ActivityCompat.requestPermissions(this, new String[]{ android.Manifest.permission.ACCESS_COARSE_LOCATION, android.Manifest.permission.ACCESS_FINE_LOCATION }, REQUEST_CODE_PERMISSION); }else{ if (checkPlayServices()){ buildGoogleApiClient(); if (locationSwitch.isChecked()){ drivers= FirebaseDatabase.getInstance().getReference(Common.driver_tbl).child(Common.currentUser.getCarType()); geoFire=new GeoFire(drivers); displayLocation(); } } } }
Example #7
Source File: GeoFireTestingRule.java From geofire-android with Apache License 2.0 | 6 votes |
/** This lets you blockingly wait until the onGeoFireReady was fired on the provided Geofire instance. */ public void waitForGeoFireReady(GeoFire geoFire) throws InterruptedException { final Semaphore semaphore = new Semaphore(0); geoFire.getDatabaseReference().addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(@NonNull DataSnapshot dataSnapshot) { semaphore.release(); } @Override public void onCancelled(@NonNull DatabaseError databaseError) { Assert.fail("Firebase error: " + databaseError); } }); Assert.assertTrue("Timeout occured!", semaphore.tryAcquire(timeout, TimeUnit.SECONDS)); }
Example #8
Source File: DriverTracking.java From UberClone with MIT License | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_driver_tracking); // Obtain the SupportMapFragment and get notified when the map is ready to be used. if(getIntent()!=null){ riderLat=getIntent().getDoubleExtra("lat",-1.0); riderLng=getIntent().getDoubleExtra("lng",-1.0); riderID = getIntent().getStringExtra("riderID"); riderToken=getIntent().getStringExtra("token"); } database = FirebaseDatabase.getInstance(); historyDriver = database.getReference(Common.history_driver).child(Common.userID); historyRider = database.getReference(Common.history_rider).child(riderID); riderInformation=database.getReference(Common.user_rider_tbl); tokens=database.getReference(Common.token_tbl); drivers= FirebaseDatabase.getInstance().getReference(Common.driver_tbl).child(Common.currentUser.getCarType()); geoFire=new GeoFire(drivers); SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); verifyGoogleAccount(); mService = Common.getGoogleAPI(); mFCMService=Common.getFCMService(); location=new Location(this, new locationListener() { @Override public void locationResponse(LocationResult response) { // refresh current location Common.currentLat=response.getLastLocation().getLatitude(); Common.currentLng=response.getLastLocation().getLongitude(); displayLocation(); } }); btnStartTrip=(Button)findViewById(R.id.btnStartTrip); btnStartTrip.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(btnStartTrip.getText().equals("START TRIP")){ pickupLocation=new LatLng(Common.currentLat, Common.currentLng); btnStartTrip.setText("DROP OFF HERE"); }else if(btnStartTrip.getText().equals("DROP OFF HERE")){ calculateCashFree(pickupLocation, new LatLng(Common.currentLat, Common.currentLng)); } } }); getRiderData(); }
Example #9
Source File: DriverMapActivity.java From UberClone with MIT License | 5 votes |
@Override public void onLocationResult(LocationResult locationResult) { for(Location location : locationResult.getLocations()){ if(getApplicationContext()!=null){ if(!customerId.equals("") && mLastLocation!=null && location != null){ rideDistance += mLastLocation.distanceTo(location)/1000; } mLastLocation = location; LatLng latLng = new LatLng(location.getLatitude(),location.getLongitude()); mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); mMap.animateCamera(CameraUpdateFactory.zoomTo(11)); String userId = FirebaseAuth.getInstance().getCurrentUser().getUid(); DatabaseReference refAvailable = FirebaseDatabase.getInstance().getReference("driversAvailable"); DatabaseReference refWorking = FirebaseDatabase.getInstance().getReference("driversWorking"); GeoFire geoFireAvailable = new GeoFire(refAvailable); GeoFire geoFireWorking = new GeoFire(refWorking); switch (customerId){ case "": geoFireWorking.removeLocation(userId); geoFireAvailable.setLocation(userId, new GeoLocation(location.getLatitude(), location.getLongitude())); break; default: geoFireAvailable.removeLocation(userId); geoFireWorking.setLocation(userId, new GeoLocation(location.getLatitude(), location.getLongitude())); break; } } } }
Example #10
Source File: DriverMapActivity.java From UberClone with MIT License | 5 votes |
private void disconnectDriver(){ if(mFusedLocationClient != null){ mFusedLocationClient.removeLocationUpdates(mLocationCallback); } String userId = FirebaseAuth.getInstance().getCurrentUser().getUid(); DatabaseReference ref = FirebaseDatabase.getInstance().getReference("driversAvailable"); GeoFire geoFire = new GeoFire(ref); geoFire.removeLocation(userId); }
Example #11
Source File: onAppKilled.java From UberClone with MIT License | 5 votes |
@Override public void onTaskRemoved(Intent rootIntent) { super.onTaskRemoved(rootIntent); String userId = FirebaseAuth.getInstance().getCurrentUser().getUid(); DatabaseReference ref = FirebaseDatabase.getInstance().getReference("driversAvailable"); GeoFire geoFire = new GeoFire(ref); geoFire.removeLocation(userId); }
Example #12
Source File: CustomerMapActivity.java From UberClone with MIT License | 5 votes |
private void endRide(){ requestBol = false; geoQuery.removeAllListeners(); driverLocationRef.removeEventListener(driverLocationRefListener); driveHasEndedRef.removeEventListener(driveHasEndedRefListener); if (driverFoundID != null){ DatabaseReference driverRef = FirebaseDatabase.getInstance().getReference().child("Users").child("Drivers").child(driverFoundID).child("customerRequest"); driverRef.removeValue(); driverFoundID = null; } driverFound = false; radius = 1; String userId = FirebaseAuth.getInstance().getCurrentUser().getUid(); DatabaseReference ref = FirebaseDatabase.getInstance().getReference("customerRequest"); GeoFire geoFire = new GeoFire(ref); geoFire.removeLocation(userId); if(pickupMarker != null){ pickupMarker.remove(); } if (mDriverMarker != null){ mDriverMarker.remove(); } mRequest.setText("call Uber"); mDriverInfo.setVisibility(View.GONE); mDriverName.setText(""); mDriverPhone.setText(""); mDriverCar.setText("Destination: --"); mDriverProfileImage.setImageResource(R.mipmap.ic_default_user); }
Example #13
Source File: RxGeoFenceOnSubscribe.java From android-rxgeofence with MIT License | 5 votes |
public RxGeoFenceOnSubscribe(Context context, String dbUrl) { FirebaseOptions options = new FirebaseOptions.Builder().setApplicationId(APP_ID) .setDatabaseUrl(dbUrl) .build(); FirebaseApp app = FirebaseUtils.getApp(context, options, APP_ID); geoFire = new GeoFire(FirebaseDatabase.getInstance(app) .getReferenceFromUrl(dbUrl + GEO_FIRE_REF)); }
Example #14
Source File: DriverHome.java From UberClone with MIT License | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_drawer_home); verifyGoogleAccount(); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); firebaseStorage=FirebaseStorage.getInstance(); storageReference=firebaseStorage.getReference(); location=new Location(this, new locationListener() { @Override public void locationResponse(LocationResult response) { // Add a icon_marker in Sydney and move the camera Common.currentLat=response.getLastLocation().getLatitude(); Common.currentLng=response.getLastLocation().getLongitude(); displayLocation(); } }); locationSwitch=findViewById(R.id.locationSwitch); locationSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { if (b){ FirebaseDatabase.getInstance().goOnline(); location.inicializeLocation(); drivers= FirebaseDatabase.getInstance().getReference(Common.driver_tbl).child(Common.currentUser.getCarType()); geoFire=new GeoFire(drivers); }else{ FirebaseDatabase.getInstance().goOffline(); location.stopUpdateLocation(); currentLocationMarket.remove(); mMap.clear(); //handler.removeCallbacks(drawPathRunnable); if (currentLocationMarket!=null)currentLocationMarket.remove(); } } }); // Obtain the SupportMapFragment and get notified when the map is ready to be used. mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); setUpLocation(); updateFirebaseToken(); }
Example #15
Source File: GeoFireTestingRule.java From geofire-android with Apache License 2.0 | 4 votes |
/** This will return you a new Geofire instance that can be used for testing. */ public GeoFire newTestGeoFire() { return new GeoFire(databaseReference.child(randomAlphaNumericString(16))); }
Example #16
Source File: GeoFireTestingRule.java From geofire-java with MIT License | 4 votes |
/** This will return you a new Geofire instance that can be used for testing. */ public GeoFire newTestGeoFire() { return new GeoFire(databaseReference.child(randomAlphaNumericString(16))); }
Example #17
Source File: GeoFireTestingRule.java From geofire-android with Apache License 2.0 | 2 votes |
/** * Removes a location on the provided Geofire instance. * This operation will run asychronously. */ public void removeLocation(GeoFire geoFire, String key) { removeLocation(geoFire, key, false); }
Example #18
Source File: GeoFireTestingRule.java From geofire-java with MIT License | 2 votes |
/** * Sets a given location key from the latitude and longitude on the provided Geofire instance. * This operation will run asychronously. */ public void setLocation(GeoFire geoFire, String key, double latitude, double longitude) { setLocation(geoFire, key, latitude, longitude, false); }
Example #19
Source File: GeoFireTestingRule.java From geofire-java with MIT License | 2 votes |
/** * Removes a location on the provided Geofire instance. * This operation will run asychronously. */ public void removeLocation(GeoFire geoFire, String key) { removeLocation(geoFire, key, false); }
Example #20
Source File: GeoFireTestingRule.java From geofire-android with Apache License 2.0 | 2 votes |
/** * Sets a given location key from the latitude and longitude on the provided Geofire instance. * This operation will run asychronously. */ public void setLocation(GeoFire geoFire, String key, double latitude, double longitude) { setLocation(geoFire, key, latitude, longitude, false); }