private void getAssignedCustomerPosition() {
AssignedCustomerPositionRef = FirebaseDatabase.getInstance().getReference().child("Customer Requests")
.child(customerID).child("l");
AssignedCustomerPositionRef.addValueEventListener(new ValueEventListener() {
@Override public void onDataChange(
@NonNull DataSnapshot datasnapshot) {
if (datasnapshot.exists())
{
List<Object> customerPositionMap = (List<Object>) datasnapshot.getValue();
double locationLat = 0;
double locationLng = 0;
if (customerPositionMap.get(0) !=null)
{
locationLat = Double.parseDouble(customerPositionMap.get(0).toString());
}
if (customerPositionMap.get(1) !=null)
{
locationLng = Double.parseDouble(customerPositionMap.get(1).toString());
}
LatLng DriverLatlng = new LatLng(locationLat, locationLng);
mMap.addMarker(new MarkerOptions().position(DriverLatlng).title("Забрать клиента отсюда"));
}
}
@Override public void onCancelled(
@NonNull DatabaseError error) {
}
});
}
@Override public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
buildGoogleApiClient();
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
mMap.setMyLocationEnabled(true);
}
@Override public void onConnected(
@Nullable Bundle bundle) {
locationRequest = new LocationRequest();
locationRequest.setInterval(1000);
locationRequest.setFastestInterval(1000);
locationRequest.setPriority(locationRequest.PRIORITY_HIGH_ACCURACY);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this);
}
@Override public void onConnectionSuspended(int i) {
}
@Override public void onConnectionFailed(
@NonNull ConnectionResult connectionResult) {
}
@Override public void onLocationChanged(Location location)
{
if (getApplicationContext() != null) {
lastLocation = location;
LatLng latLng = new LatLng(location.getLatitude(), location.getAltitude());
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(12));
String userID = FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference DriversAvailableRef = FirebaseDatabase.getInstance().getReference().child("Driver Available");
GeoFire geoFireAvailablity = new GeoFire(DriversAvailableRef);
geoFireAvailablity.setLocation(userID, new GeoLocation(location.getLatitude(), location.getLongitude()));
DatabaseReference DriverWorkingRef = FirebaseDatabase.getInstance().getReference().child("Driver Working");
GeoFire geoFireWorking = new GeoFire(DriverWorkingRef);