SupportMapFragment mapFragment = SupportMapFragment.newInstance();
mapFragment.getMapAsync(this);
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.google_map, mapFragment);
transaction.commit();
mTimeSelect = view.findViewById(R.id.time_options);
mTimeSelect.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (position == 0) {
mShowType = SHOW_DAILY_TYPE;
} else {
mShowType = SHOW_HOURLY_TYPE;
}
getResidents();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
getResidents();
getCurrentLocation();
return view;
}
private void getCurrentLocation() {
mAddress = RestClient.getLoginResident().getAddress();
AddressLocationUtils.getLocationByAddress(getContext(), RestClient.getLoginResident().getAddress(),
new IGetLocationCallback() {
@Override
public void onGetLocation(double latitude, double longitude) {
mCurrentLatitude = latitude;
mCurrentLongitude = longitude;
showCurrentLocation();
}
});
}
private void showCurrentLocation() {
if (mMap == null) {
return;
}
mHandler.post(new Runnable() {
@Override
public void run() {
LatLng curLocation = new LatLng(mCurrentLatitude, mCurrentLongitude);
MarkerOptions markerOptions = new MarkerOptions().position(curLocation);
markerOptions.title("Current Location");
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
mMap.addMarker(markerOptions);
mMap.moveCamera(CameraUpdateFactory.newLatLng(curLocation));
mMap.animateCamera(CameraUpdateFactory.zoomTo(mMap.getMaxZoomLevel() * 0.8f), 500, null);
}
});
}