fatesses 2018-05-02 01:09 采纳率: 50%
浏览 772
已采纳

求大佬帮忙给每段代码添加下注释。。。。。。

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);
        }
    });

}
  • 写回答

2条回答 默认 最新

  • Drink1993 2018-05-02 01:52
    关注

    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);//地图移动设置动画
        }
    });
    

    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误