From 2dcfcc151b4389c2653afb461f4ee424c609a81f Mon Sep 17 00:00:00 2001 From: simcoder Date: Sat, 14 Apr 2018 19:53:10 +0100 Subject: [PATCH] - Display all drivers in customer Map --- .../simcoder/uber/CustomerMapActivity.java | 73 +++++++++++++++++-- 1 file changed, 68 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/simcoder/uber/CustomerMapActivity.java b/app/src/main/java/com/simcoder/uber/CustomerMapActivity.java index 3290832..4152d2d 100644 --- a/app/src/main/java/com/simcoder/uber/CustomerMapActivity.java +++ b/app/src/main/java/com/simcoder/uber/CustomerMapActivity.java @@ -66,6 +66,7 @@ import com.google.firebase.database.ValueEventListener; import java.text.ParseException; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -149,7 +150,7 @@ public void onClick(View v) { public void onClick(View v) { if (requestBol){ - endRide(); + endRide(); }else{ @@ -183,7 +184,7 @@ public void onClick(View v) { mSettings.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Intent intent = new Intent(CustomerMapActivity.this, CustomerSettingsActivity.class); + Intent intent = new Intent(CustomerMapActivity.this, CustomerSettingsActivity.class); startActivity(intent); return; } @@ -215,6 +216,7 @@ public void onError(Status status) { } }); + } private int radius = 1; private Boolean driverFound = false; @@ -294,7 +296,6 @@ public void onGeoQueryError(DatabaseError error) { } }); } - /*-------------------------------------------- Map specific functions ----- | Function(s) getDriverLocation | @@ -503,8 +504,10 @@ public void onLocationResult(LocationResult locationResult) { LatLng latLng = new LatLng(location.getLatitude(),location.getLongitude()); - mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); - mMap.animateCamera(CameraUpdateFactory.zoomTo(11)); + //mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); + //mMap.animateCamera(CameraUpdateFactory.zoomTo(11)); + if(!getDriversAroundStarted) + getDriversAround(); } } } @@ -558,4 +561,64 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis } } } + + + + + boolean getDriversAroundStarted = false; + List markers = new ArrayList(); + private void getDriversAround(){ + getDriversAroundStarted = true; + DatabaseReference driverLocation = FirebaseDatabase.getInstance().getReference().child("driversAvailable"); + + GeoFire geoFire = new GeoFire(driverLocation); + GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(mLastLocation.getLongitude(), mLastLocation.getLatitude()), 999999999); + + geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() { + @Override + public void onKeyEntered(String key, GeoLocation location) { + + for(Marker markerIt : markers){ + if(markerIt.getTag().equals(key)) + return; + } + + LatLng driverLocation = new LatLng(location.latitude, location.longitude); + + Marker mDriverMarker = mMap.addMarker(new MarkerOptions().position(driverLocation).title(key).icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_car))); + mDriverMarker.setTag(key); + + markers.add(mDriverMarker); + + + } + + @Override + public void onKeyExited(String key) { + for(Marker markerIt : markers){ + if(markerIt.getTag().equals(key)){ + markerIt.remove(); + } + } + } + + @Override + public void onKeyMoved(String key, GeoLocation location) { + for(Marker markerIt : markers){ + if(markerIt.getTag().equals(key)){ + markerIt.setPosition(new LatLng(location.latitude, location.longitude)); + } + } + } + + @Override + public void onGeoQueryReady() { + } + + @Override + public void onGeoQueryError(DatabaseError error) { + + } + }); + } }