zoukankan      html  css  js  c++  java
  • 获取设备信息 以及 获取地 理位置

    一、Flutter 中获取设备信息
    https://pub.dev/packages/device_info
     
    设备信息代码
    import 'package:flutter/material.dart';
    import 'package:device_info/device_info.dart';

    class DevicPage extends StatefulWidget{
    DevicPage({Key key});
    _DevicPage createState() => _DevicPage();
    }

    class _DevicPage extends State {
    var _text;
    @override
    initState() {
    super.initState();
    _getDevice();
    }
    _getDevice() async{
    DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
    AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
    print('设备信息 ${androidInfo}');
    _text = androidInfo;
    }
    Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
    appBar: AppBar(title: Text('device'),),
    body: ListView(
    children: <Widget>[
    Text('${_text.version}'),
    Text('${_text.board}'),
    Text('${_text.bootloader}'),
    Text('${_text.brand}'),
    Text('${_text.device}'),
    Text('${_text.display}'),
    Text('${_text.fingerprint}'),
    Text('${_text.hardware}'),
    Text('${_text.host}'),
    Text('${_text.id}'),
    Text('${_text.manufacturer}'),
    Text('${_text.model}'),
    Text('${_text.product}'),
    Text('${_text.tags}'),
    Text('${_text.type}'),
    Text('${_text.isPhysicalDevice}'),
    Text('${_text.androidId}'),
    ],
    )
    );
    }
    }

    二、Flutter 中获取设备信息
       https://pub.dev/packages/device_info
     
    三、Flutter 中使用高德定位准备工作获取 key
      1、申请成为开发者
      2、创建应用配置获取 Key (参考教程演示)
    https://lbs.amap.com/api/android-sdk/guide/create-project/get-key
     
    四、Flutter 实现用高德定位
      https://pub.dev/packages/amap_location
     
    注意点 
    manifestPlaceholders = [AMAP_KEY : "ad2d13e8fab8a607b4707a598e32fc70"]  // 自己的高德key
    注意 添加 dependencies 到 andriod 里面 和 manifestPlaceholders = [AMAP_KEY : "ad2d13e8fab8a607b4707a598e32fc70"] 配置同级,不是外层的 dependencies
    dependencies {
    /// 注意这里需要在主项目增加一条依赖,否则可能发生编译不通过的情况
    implementation 'com.amap.api:location:latest.integration'
    }
    定位案例代码
    import 'package:flutter/material.dart';
    import 'package:amap_location/amap_location.dart';

    class GpsPage extends StatefulWidget{
    GpsPage({Key key});
    _GpsPage createState() => _GpsPage();
    }

    class _GpsPage extends State {
    var gps;
    @override
    initState() {
    super.initState();
    _getGps();
    }
    _getGps() async{
    var reult = await AMapLocationClient.startup(new AMapLocationOption( desiredAccuracy:CLLocationAccuracy.kCLLocationAccuracyHundredMeters ));
    var res = await AMapLocationClient.getLocation(true);
    // print(res.accuracy);
    setState(() {
    gps = res;
    });
    }
    Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
    appBar: AppBar(title: Text('device'),),
    body: ListView(
    children: <Widget>[
    Text('${gps.longitude}'),
    Text('${gps.latitude}'),
    Text('${gps.accuracy}'),
    ],
    )
    );
    }
    }
  • 相关阅读:
    C++中的深拷贝和浅拷贝构造函数
    C++中构造函数的手动和自动调用方式
    C++中的构造函数
    P1709 [USACO5.5]隐藏口令Hidden Password
    [TJOI2007]segment
    11.28
    1565
    某数学题1
    某模拟题
    某看起来会做的数据结构题
  • 原文地址:https://www.cnblogs.com/zhaofeis/p/12369842.html
Copyright © 2011-2022 走看看