Skip to content

Commit

Permalink
- Display all drivers in customer Map
Browse files Browse the repository at this point in the history
  • Loading branch information
SimCoderYoutube committed Apr 14, 2018
1 parent 17aa30a commit 2dcfcc1
Showing 1 changed file with 68 additions and 5 deletions.
73 changes: 68 additions & 5 deletions app/src/main/java/com/simcoder/uber/CustomerMapActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -149,7 +150,7 @@ public void onClick(View v) {
public void onClick(View v) {

if (requestBol){
endRide();
endRide();


}else{
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -215,6 +216,7 @@ public void onError(Status status) {
}
});


}
private int radius = 1;
private Boolean driverFound = false;
Expand Down Expand Up @@ -294,7 +296,6 @@ public void onGeoQueryError(DatabaseError error) {
}
});
}

/*-------------------------------------------- Map specific functions -----
| Function(s) getDriverLocation
|
Expand Down Expand Up @@ -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();
}
}
}
Expand Down Expand Up @@ -558,4 +561,64 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
}
}
}




boolean getDriversAroundStarted = false;
List<Marker> markers = new ArrayList<Marker>();
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) {

}
});
}
}

0 comments on commit 2dcfcc1

Please sign in to comment.