• 项目总结3


    1.继续体温填报项目

    在我xml布局中显示文本类型的地图代码:

    mLocationClient = new LocationClient((getApplicationContext()));
    mLocationClient.registerNotifyLocationListener((BDLocationListener) new MyLocationListener());
    mbutt = (Button) findViewById(R.id.butt_1);//找到组件
    mbutt.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    Toast.makeText(MainActivity.this, "记录成功", Toast.LENGTH_SHORT).show();
    }
    });//点击发生的事件
    positionText = (TextView)findViewById(R.id.position_text_view);
    List<String> permissionList = new ArrayList<>();
    //如果没有启动下面权限,就询问用户让用户打开
    if(ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION)!= PackageManager.PERMISSION_GRANTED)
    {
    permissionList.add(Manifest.permission.ACCESS_FINE_LOCATION);
    }
    if(ContextCompat.checkSelfPermission(MainActivity.this,Manifest.permission.READ_PHONE_STATE)!= PackageManager.PERMISSION_GRANTED)
    {
    permissionList.add(Manifest.permission.READ_PHONE_STATE);
    }
    if (ContextCompat.checkSelfPermission(MainActivity.this,
    Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
    permissionList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
    }
    if (!permissionList.isEmpty()) {
    String[] permissions = permissionList.toArray(new String[permissionList.size()]);
    ActivityCompat.requestPermissions(MainActivity.this, permissions, 1);
    }
    else {
    requestLocation();
    }

    }
    /*初始化函数,并启动位置客户端LocationClient*/
    private void requestLocation() {
    initLocation();
    mLocationClient.start();
    }

    /*初始化函数*/
    private void initLocation() {
    LocationClientOption option = new LocationClientOption();
    option.setScanSpan(5000);
    option.setIsNeedAddress(true);
    mLocationClient.setLocOption(option);
    }

    /*只有同意打开相关权限才可以开启本程序*/
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    switch (requestCode) {
    case 1:
    if (grantResults.length > 0) {
    for (int result : grantResults) {
    if (result != PackageManager.PERMISSION_GRANTED) {
    Toast.makeText(this, "必须同意所有权限才能使用本程序", Toast.LENGTH_SHORT).show();
    finish();
    return;
    }
    }
    requestLocation();
    } else {
    Toast.makeText(this, "发生未知错误", Toast.LENGTH_SHORT).show();
    finish();
    }
    break;
    default:
    }
    }

    /*监听线程,获得当前的经纬度,并显示*/
    public class MyLocationListener implements BDLocationListener {
    @Override
    public void onReceiveLocation(final BDLocation location) {
    runOnUiThread(new Runnable() {
    @Override
    public void run() {
    currentPosition = new StringBuilder();
    currentPosition.append("纬度:").append(location.getLatitude()).append(" ");
    currentPosition.append("经度:").append(location.getLongitude()).append(" ");
    currentPosition.append("国家:").append(location.getCountry()).append(" ");
    currentPosition.append(":").append(location.getProvince()).append(" ");
    currentPosition.append(":").append(location.getCity()).append(" ");
    currentPosition.append(":").append(location.getDistrict()).append(" ");
    currentPosition.append("街道:").append(location.getStreet()).append(" ");
    currentPosition.append("定位方式:");
    if (location.getLocType() == BDLocation.TypeGpsLocation) {
    currentPosition.append("GPS");
    } else if (location.getLocType() == BDLocation.TypeNetWorkLocation) {
    currentPosition.append("网络");
    }
    positionText.setText(currentPosition);
    }
    });
    }
    }



    public void onConnectHotSpotMessage(String s, int i) {

    }
    @Override
    protected void onDestroy(){
    super.onDestroy();
    mLocationClient.stop();
    }
  • 相关阅读:
    while(~scanf(..))为什么可以这样写
    【 HDU3294 】Girls' research (Manacher)
    【 HDU2966 】In case of failure(KD-Tree)
    【 HDU 1538 】A Puzzle for Pirates (海盗博弈论)
    【 HDU 2177 】取(2堆)石子游戏 (威佐夫博弈)
    【 HDU 4936 】Rainbow Island (hash + 高斯消元)
    【 HDU1081 】 To The Max (最大子矩阵和)
    Partition Numbers的计算
    【 HDU
    【 Gym 101116K 】Mixing Bowls(dfs)
  • 原文地址:https://www.cnblogs.com/chenghaixiang/p/14908876.html
Copyright © 2020-2023  润新知