flutter_weather 入门实战项目的记录

flutter_weather 入门实战项目的记录

Long
Long  

# 项目的搭建

flutter create weather

# 利用的amap_location来获取经纬度

  • 安装 amap_location
flutter pub add amap_location
import 'package:amap_location/amap_location.dart';
void main() {
  // 设置 apiKey
  AMapLocationClient.setApiKey("0bbfb325da9b8a9d552e8ea379eb6ca1");
  runApp(MyApp());
}
  • ios的话 需要在 Info.list 添加的下面的代码
<key>NSLocationWhenInUseUsageDescription</key>
<string>要用定位</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescriptio</key>
<string>要用定位</string>
  • 在需要获取经纬度地方获取
AMapLocation location; // 定义的location变量
void _checkPersmission() async {
  // 先启动
  await AMapLocationClient.startup(
    new AMapLocationOption(
      desiredAccuracy: CLLocationAccuracy.kCLLocationAccuracyHundredMeters,
    ),
  );
  // 直接获取
  AMapLocation loc = await AMapLocationClient.getLocation(true);
  setState(() {
    location = loc;
    print(location.latitude);
    print(location.longitude);
    AMapLocationClient.stopLocation();// 停止监听
  });
}