求大佬帮忙给每段代码添加下注释。。。。。。
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);
}
});
}
SupportMapFragment mapFragment = SupportMapFragment.newInstance();//通过SupportMapFragment获取单列地图fragment
mapFragment.getMapAsync(this);//通过地图fragment获取Map地图
FragmentTransaction transaction = getFragmentManager().beginTransaction();//获取fragment管理器,再得到fragment事务管理
transaction.replace(R.id.google_map, mapFragment);//找到R.id.google_map,替换成地图fragment
transaction.commit();//fragment事务管理提交
mTimeSelect = view.findViewById(R.id.time_options);//找到时间选择器mTimeSelect
//选择器mTimeSelect设置监听
mTimeSelect.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (position == 0) {//如果选择0号位置
mShowType = SHOW_DAILY_TYPE;//展示类型设置为 选择 天 类型的
} else {//选择非0以外的其他位置
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) {//如果地图map没有初始化,直接返回
return;
}
mHandler.post(new Runnable() {//开启子线程中执行任务
@Override
public void run() {//任务开始执行
LatLng curLocation = new LatLng(mCurrentLatitude, mCurrentLongitude);//通过当前经纬度,获取高德经纬度封装类LatLng的对象curLocation
MarkerOptions markerOptions = new MarkerOptions().position(curLocation);//通过当前经纬度创建一个标记点
markerOptions.title("Current Location");//标记点标题是"Current Location"
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));//标记点设置默认图标为BitmapDescriptorFactory.HUE_BLUE
mMap.addMarker(markerOptions);//地图上添加标记点
mMap.moveCamera(CameraUpdateFactory.newLatLng(curLocation));//地图焦点移动到当前定位位置
mMap.animateCamera(CameraUpdateFactory.zoomTo(mMap.getMaxZoomLevel() * 0.8f), 500, null);//地图移动设置动画
}
});
}
mTimeSelect = view.findViewById(R.id.time_options);//找到时间选择器mTimeSelect
//选择器mTimeSelect设置监听
mTimeSelect.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (position == 0) {//如果选择0号位置
mShowType = SHOW_DAILY_TYPE;//展示类型设置为 选择 天 类型的
} else {//选择非0以外的其他位置
mShowType = SHOW_HOURLY_TYPE;//展示类型设置为 选择 小时 类型的
}
getResidents();//获取用户数据
}
@Override
public void onNothingSelected(AdapterView<?> parent) {//没有挑选什么也不做
}
});
getResidents();//获取用户数据
getCurrentLocation();//获取当前定位信息数据
return view;