flutter_tenc_map 0.0.8

  • Readme
  • Changelog
  • Example
  • Installing
  • 63

flutter_tenc_map #

腾讯地图定位

![pub package]

android:配置地图Key #

在AndroidManifest.xml中配置

    <application
            ...
        <meta-data
            android:name="TencentMapSDK"
            android:value="H5PBZ-PNV3V-F2WPG-UUZCN-O6MPQ-LLB3Q" />
            ...
    </application>
value为腾讯地图的KEY值

使用方法 #

1.导入包

import 'package:flutter_tenc_map/flutter_tenc_map.dart';

使用前初始化

FlutterTencMap.init("");

3.请求定位

  Location location = await FlutterTencMap.getLocation(1000);

参数为多久请求一次,默认10000毫秒

4.添加定位监听

   FlutterTencMap.locationController.listener.add((location) {
        //work
      });

5.停止定位

  bool isOK = await FlutterTencMap.stopLocation();

0.0.2 #

0.0.3 #

location增加 定位状态 code

0.0.4 #

1.增加对模拟器的调试 2.增加android对3D地图的显示 3.在地图上标记点

0.0.5 #

1.增加android3D地图显示

0.0.6 #

1.修复地图定位异常问题

0.0.7 #

1.删改定位日志打印

0.0.8 #

1.kotlin版本至1.3.10

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:flutter_tenc_map/flutter_tenc_map.dart';

import 'map_page.dart';

void main() async {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    FlutterTencMap.init("5J2BZ-RKD63-6WU3E-YM6GU-COWVQ-ZSFS5");

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(home: MainPage());
  }
}

class MainPage extends StatefulWidget {
  @override
  _MainPageState createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  String _platformVersion = 'Unknown';

  Location location;

  LocationController locationController = LocationController();

  String status = "定位中...";

  @override
  void initState() {
    super.initState();
    FlutterTencMap.locationController.listener.add((location) {
      this.location = location;
      switch (location.code) {
        case 0:
          status = "无法定位";
          break;
        case 1:
          status = "缺少权限";
          break;
        case 2:
          status = "网络错误";
          break;
        case 3:
          status = "无法获取方向";
          break;
        case 4:
          status = "未知错误";
          break;
        case 200:
          status = "正常";
          break;
      }
      setState(() {});
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Plugin example app'),
      ),
      body: Center(
          child: Column(
        children: <Widget>[
          RaisedButton(
            onPressed: () {
              getLocation();
            },
            child: Text("获取位置"),
          ),
          Text("位置为:" +
              (location == null
                  ? "未定位"
                  : (location.address ?? "") +
                      ("经度:${location.longitude} ") +
                      "纬度:${location.latitude}")),
          Text("状态:$status"),
          RaisedButton(
            onPressed: () {
              stopLocation();
            },
            child: Text("停止获取"),
          ),
          RaisedButton(
            onPressed: () {
              Navigator.push(
                  context, MaterialPageRoute(builder: (_) => MapPage()));
            },
            child: Text("打开地图"),
          )
        ],
      )),
    );
  }

  @override
  void dispose() {
    FlutterTencMap.distory();
    print("调用停止");
    super.dispose();
  }

  getLocation() async {
    location = await FlutterTencMap.getLocation(2000);
    setState(() {});
  }

  void stopLocation() async {
    bool isOK = await FlutterTencMap.stopLocation();
    if (isOK) {
      print("停止成功");
    }
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_tenc_map: ^0.0.8

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_tenc_map/flutter_tenc_map.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
40
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
63
Learn more about scoring.

We analyzed this package on Mar 31, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health suggestions

Fix lib/controll/location_controller.dart. (-0.50 points)

Analysis of lib/controll/location_controller.dart reported 1 hint:

line 2 col 8: Unused import: 'package:flutter/material.dart'.

Fix lib/map_view/map_view.dart. (-0.50 points)

Analysis of lib/map_view/map_view.dart reported 1 hint:

line 5 col 8: Unused import: 'package:flutter_tenc_map/model/location.dart'.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test