flutter_dhl_amap 0.0.1 flutter_dhl_amap: ^0.0.1 copied to clipboard
amap
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/flutter_dhl_amap.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/Search/DHL_Measure_Model.dart';
void main(){
new FlutterDhlAmap();
FlutterDhlAmap.setInit("794d0fa25ca3a4ad4002939fbe0a8c67");//初始化
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
var _result = "";
var m_key = 0;
@override
void initState() {
super.initState();
FlutterDhlAmap.startLocation(DHL_AMapLocationOption(//设置参数
));//开始定位
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;
});
}
DHL_aMapView dhl_aMapView;
@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,
),
),
);;
}
}