use of com.jexapps.bloodhub.m_Model.BloodRequest in project BloodHub by kazijehangir.
the class RequestMapFragment method setupMap.
public void setupMap() {
Log.d("JK", "setupMap: called ");
try {
MapsInitializer.initialize(getActivity().getApplicationContext());
} catch (Exception e) {
e.printStackTrace();
}
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap mMap) {
googleMap = mMap;
if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
googleMap.setMyLocationEnabled(true);
}
// For dropping a marker at a point on the Map
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
Date startDate = cal.getTime();
FirebaseDatabase.getInstance().getReference().child("bloodrequests").orderByChild("date").startAt(startDate.getTime()).limitToFirst(15).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot child : dataSnapshot.getChildren()) {
BloodRequest request = child.getValue(BloodRequest.class);
if (request.latitude != -1 && request.longitude != -1) {
String needs = request.quantity + " bags of " + request.blood_group;
Marker marker = googleMap.addMarker(new MarkerOptions().position(new LatLng(request.latitude, request.longitude)).title(request.name).snippet(needs));
marker.setTag(child.getKey());
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
// if we can't access the location yet
if (!location.hasLocationEnabled()) {
// ask the user to enable location access
SimpleLocation.openSettings(getContext());
}
final double latitude = location.getLatitude();
final double longitude = location.getLongitude();
CameraPosition cameraPosition = new CameraPosition.Builder().target(new LatLng(latitude, longitude)).zoom(12).build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
googleMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
Intent intent = new Intent(getContext(), RequestDetail.class);
intent.putExtra("request", (String) marker.getTag());
getContext().startActivity(intent);
}
});
}
});
}
Aggregations