| | |
| | | import 'dart:async'; |
| | | import 'dart:io'; |
| | | import 'dart:typed_data'; |
| | | import 'dart:ui'; |
| | | |
| | | import 'package:flutter/cupertino.dart'; |
| | |
| | | import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; |
| | | import 'package:flutter_baidu_mapapi_map/flutter_baidu_mapapi_map.dart'; |
| | | import 'package:flutter_baidu_mapapi_search/flutter_baidu_mapapi_search.dart'; |
| | | import 'package:fluttertoast/fluttertoast.dart'; |
| | | import 'package:locations/ui/map/location_search.dart'; |
| | | import 'package:locations/ui/map/travel.dart'; |
| | | import 'package:locations/ui/mine/advice.dart'; |
| | | import 'package:locations/ui/mine/permission.dart'; |
| | | import 'package:locations/ui/mine/settings.dart'; |
| | | import 'package:locations/ui/mine/share_to_friends.dart'; |
| | | import 'package:locations/ui/mine/try_functions.dart'; |
| | | import 'package:locations/ui/widget/button.dart'; |
| | | import 'package:locations/ui/widget/custom.dart'; |
| | | import 'package:locations/ui/widget/capture.dart'; |
| | | import 'package:locations/ui/widget/map_marker.dart'; |
| | | import 'package:locations/utils/global.dart'; |
| | | import 'package:locations/utils/location_util.dart'; |
| | | import 'package:locations/utils/map_util.dart'; |
| | | import 'package:locations/utils/pageutils.dart'; |
| | | import 'package:locations/utils/ui_constant.dart'; |
| | | import 'package:path_provider/path_provider.dart'; |
| | | import 'package:permission_handler/permission_handler.dart'; |
| | | import 'package:fluttertoast/fluttertoast.dart'; |
| | | |
| | | //控件阴影 |
| | | List<BoxShadow> getViewShadow() { |
| | |
| | | BMFMapOptions mapOptions = BMFMapOptions( |
| | | showMapScaleBar: false, |
| | | mapType: BMFMapType.Standard, |
| | | center: BMFCoordinate(39.917215, 116.380341), |
| | | center: Global.currentPosition != null |
| | | ? Global.currentPosition |
| | | : BMFCoordinate(39.917215, 116.380341), |
| | | mapScaleBarPosition: BMFPoint(0, 200), |
| | | zoomLevel: 12, |
| | | mapPadding: BMFEdgeInsets(left: 30, top: 0, right: 30, bottom: 200)); |
| | |
| | | |
| | | //是否正在录制轨迹 |
| | | bool travelRECIng = false; |
| | | List<BMFMarker> startMarkers = []; |
| | | |
| | | TravelRECManager? _travelRECManager; |
| | | |
| | | //用戶目前的位置 |
| | | BMFCoordinate? currentPosition; |
| | | |
| | | TextEditingController? editingController; |
| | | List<BMFPoiInfo>? suggestList; |
| | | |
| | | AnimationController? _animationController; |
| | | Animation<double>? _animation; |
| | | |
| | | BMFMarker? userMarker; |
| | | |
| | | //当前用户头像 |
| | | |
| | | CaptureController _captureController = CaptureController(); |
| | | |
| | | @override |
| | | void initState() { |
| | | super.initState(); |
| | | editingController = TextEditingController(); |
| | | _animationController = new AnimationController( |
| | | duration: const Duration(milliseconds: 300), vsync: this); |
| | | final CurvedAnimation curve = |
| | |
| | | }); |
| | | } |
| | | |
| | | @override |
| | | void dispose() { |
| | | super.dispose(); |
| | | if (null != subscription) { |
| | | subscription!.cancel(); |
| | | } |
| | | LocationUtil.stopLocation(); |
| | | } |
| | | |
| | | //获取地图视图 |
| | | Widget getMapView() { |
| | | return Container( |
| | | child: BMFMapWidget( |
| | | onBMFMapCreated: (controller) { |
| | | _mapController = controller; |
| | | _startLocation(); |
| | | drawLine(); |
| | | _travelRECManager = TravelRECManager(_mapController); |
| | | _startLocation(0); |
| | | }, |
| | | mapOptions: mapOptions, |
| | | ), |
| | | ); |
| | | } |
| | | |
| | | void _startLocation() { |
| | | StreamSubscription<Map<String, Object>?>? subscription; |
| | | |
| | | void _startLocation(int scanspan) async { |
| | | //启动定位 |
| | | LocationUtil.init(0); |
| | | LocationUtil.startLocation((map) { |
| | | double lat = map["latitude"] as double; |
| | | double lng = map["logitude"] as double; |
| | | _mapController!.setCenterCoordinate(BMFCoordinate(lng, lat), true); |
| | | if (subscription != null) { |
| | | subscription!.cancel(); |
| | | } |
| | | subscription = await LocationUtil.startLocation( scanspan, (state, map) { |
| | | if (state == LocationState.success) { |
| | | double lat = map!["latitude"] as double; |
| | | double lng = map!["longitude"] as double; |
| | | currentPosition = BMFCoordinate(lat, lng); |
| | | _mapController!.setCenterCoordinate(BMFCoordinate(lat, lng), true); |
| | | setCurrentPosition(BMFCoordinate(lat, lng)); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | void drawLine() { |
| | | List<BMFCoordinate> coordinates = []; |
| | | coordinates.add(BMFCoordinate(29.523624, 106.48916)); |
| | | coordinates.add(BMFCoordinate(29.535189, 106.502095)); |
| | | coordinates.add(BMFCoordinate(29.545747, 106.528829)); |
| | | coordinates.add(BMFCoordinate(29.556304, 106.545789)); |
| | | coordinates.add(BMFCoordinate(29.565101, 106.566486)); |
| | | coordinates.add(BMFCoordinate(29.568619, 106.588045)); |
| | | coordinates.add(BMFCoordinate(29.578922, 106.580284)); |
| | | coordinates.add(BMFCoordinate(29.587968, 106.575972)); |
| | | coordinates.add(BMFCoordinate(29.596762, 106.568211)); |
| | | coordinates.add(BMFCoordinate(29.607062, 106.567923)); |
| | | coordinates.add(BMFCoordinate(29.614096, 106.574247)); |
| | | MapUtil.drawLine(coordinates, ColorConstant.theme, _mapController); |
| | | MapUtil.getMapShowParams(coordinates).then((value) { |
| | | _mapController!.setCenterCoordinate(value!.center!, true); |
| | | _mapController!.setZoomTo(value.zoomLevel!.toDouble()); |
| | | }); |
| | | void stopLocation() async { |
| | | if (subscription != null) { |
| | | subscription!.cancel(); |
| | | } |
| | | LocationUtil.stopLocation(); |
| | | } |
| | | |
| | | setCurrentPosition(BMFCoordinate position) async { |
| | | Directory? tempDir = await getExternalStorageDirectory(); |
| | | String tempPath = tempDir!.path; |
| | | if (userMarker == null) { |
| | | _captureController.capturePng(tempPath + "/portrait.png").then((value) { |
| | | MapUtil.addMarker(_mapController, position, value!.path, |
| | | offset: BMFPoint(0, 40), zIndex: 10); |
| | | }); |
| | | } else { |
| | | await userMarker!.updatePosition(position); |
| | | } |
| | | } |
| | | |
| | | @override |
| | |
| | | ) |
| | | ], |
| | | ))), |
| | | Positioned(top: 100, child: |
| | | PersonLocationMarker()) |
| | | Positioned( |
| | | top: -100, |
| | | child: CaptureWidget( |
| | | widget: PersonLocationMarker(Image.asset( |
| | | "assets/images/mine/icon_mine_default_portrait.png", |
| | | )), |
| | | captureController: _captureController, |
| | | )) |
| | | ])); |
| | | } |
| | | |
| | |
| | | InkWell( |
| | | onTap: () { |
| | | if (!travelRECIng) { |
| | | currentPosition = BMFCoordinate(29.523624, 106.48916); |
| | | if (currentPosition == null) { |
| | | Fluttertoast.showToast(msg: "定位失败,请重新定位"); |
| | | return; |
| | | } |
| | | MapUtil.addMarker(_mapController, currentPosition!, |
| | | "assets/images/map/icon_travel_start.png", |
| | | zIndex: 1) |
| | | .then((value) { |
| | | startMarkers.add(value); |
| | | }); |
| | | MapUtil.addMarker(_mapController, currentPosition!, |
| | | "assets/images/map/icon_travel_start_1.png", |
| | | offset: BMFPoint(0, 38)) |
| | | .then((value) { |
| | | startMarkers.add(value); |
| | | //开始定位 |
| | | LocationUtil.startLocation(0, (state, map) { |
| | | if (state == LocationState.success) { |
| | | double lat = map!["latitude"] as double; |
| | | double lng = map!["longitude"] as double; |
| | | currentPosition = BMFCoordinate(lat, lng); |
| | | _mapController!.setCenterCoordinate( |
| | | BMFCoordinate(lat, lng), true); |
| | | setCurrentPosition(BMFCoordinate(lat, lng)); |
| | | |
| | | //开始录制 |
| | | _travelRECManager!.startREC(currentPosition!); |
| | | //启动定位 |
| | | _startLocation(1000 * 30); |
| | | } else { |
| | | Fluttertoast.showToast(msg: "定位失败,请重新定位"); |
| | | return; |
| | | } |
| | | }); |
| | | } else { |
| | | //结束录制 |
| | | if (startMarkers.length > 0) |
| | | MapUtil.removeMarkers(_mapController, startMarkers); |
| | | _travelRECManager!.stopREC(); |
| | | //结束定位 |
| | | stopLocation(); |
| | | } |
| | | |
| | | setState(() { |
| | |
| | | ), |
| | | InkWell( |
| | | onTap: () { |
| | | _startLocation(); |
| | | _startLocation(0); |
| | | }, |
| | | child: Column( |
| | | children: [ |