flutter_dhl_amap 0.0.11 copy "flutter_dhl_amap: ^0.0.11" to clipboard
flutter_dhl_amap: ^0.0.11 copied to clipboard

amap

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:flutter_dhl_amap/DHL_Location.dart';
import 'package:flutter_dhl_amap/DHL_Location_Model.dart';
import 'package:flutter_dhl_amap/Search/DHL_Measure_Model.dart';
import 'package:flutter_dhl_amap/aMap/DHL_aMapView.dart';
import 'package:flutter_dhl_amap/aMap/DHL_aMapView_Model.dart';
import 'package:flutter_dhl_amap/flutter_dhl_amap.dart';

void main(){
  WidgetsFlutterBinding.ensureInitialized();

  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  var _result = "";
  var m_key = 0;
  late DHL_aMapView dhl_aMapView;
  @override
  void initState() {
    super.initState();


    initPlatformState();
    new FlutterDhlAmap();
    FlutterDhlAmap.setInit("5a7ad9d014cfe8083741e895cfc15ee2");//初始化


    FlutterDhlAmap.startLocation(DHL_AMapLocationOption(//设置参数
        interval:10000,
        onceLocationLatest:true,
        locationCacheEnable:false,
        allowsBackgroundLocationUpdates:true,
        locationTimeout:2,
        reGeocodeTimeout:2
    ));//开始定位
    FlutterDhlAmap.onLocationUpate.listen((DHL_Location_Model data){
      if(!mounted)return;
      print(data.formattedAddress);
      dhl_aMapView.SetCoordinate(data.lat,data.lon);//定图设置定位
      dhl_aMapView.SetMymarkerContent(data.lat.toString(),data.lon.toString());


      setState(() {
        m_key++;
        _result = data.formattedAddress;
      });

    });
    FlutterDhlAmap.onLocationUpate_Measure.listen((List<DHL_Measure_Model> data){//计算两个坐标的回调
      List<DHL_Measure_Model> dat =  data;
    });

    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await FlutterDhlAmap.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }



  @override
  Widget build(BuildContext context) {

    dhl_aMapView = DHL_aMapView(dhlAMapViewModel: DHL_aMapView_Model(
      setZoomControlsEnabled :true,
      setCompassEnabled :true,
      setMyLocationButtonEnabled :true,
      setScaleControlsEnabled :true,
      setZoomGesturesEnabled :true, ));

    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Row(children: <Widget>[
            RaisedButton(onPressed:() async{
              dhl_aMapView.AddMarker(22.160258,113.347154, "标题","内容", "0", true);//添加坐标点



              dhl_aMapView.UpdateMarker(22.160257, 113.347154, "更新到了", "更新到了", "0");//更新坐标点

              FlutterDhlAmap.Calculation_location(22.160258,113.347154, 23.697839,113.0441, 1);

              //Map<dynamic, dynamic> dmap =  await FlutterDhlAmap.changeLocation(22.160258,113.347154,  "baidu");//转换坐标
            },child: Text('Plugin example app:') ),




            RaisedButton(onPressed:() {

              dhl_aMapView.DelMarkerShow("0");//删除全部

            },child: Text('22222') ),


          ],)  ,
        ),
        body:Center(
          child: dhl_aMapView,
        ),
      ),
    );
  }
}