去掉搜索 和 定位
This commit is contained in:
@ -8,8 +8,8 @@ Future<void> main() async {
|
||||
runApp(MyApp());
|
||||
|
||||
await enableFluttifyLog(false);
|
||||
await AmapSearch.instance.updatePrivacyAgree(true);
|
||||
await AmapSearch.instance.updatePrivacyShow(true);
|
||||
// await AmapSearch.instance.updatePrivacyAgree(true);
|
||||
// await AmapSearch.instance.updatePrivacyShow(true);
|
||||
await AmapService.instance.init(
|
||||
iosKey: '7a04506d15fdb7585707f7091d715ef4',
|
||||
androidKey: '7c9daac55e90a439f7b4304b465297fa',
|
||||
|
@ -390,51 +390,51 @@ class _CreateMapScreenState extends State<CreateMapScreen>
|
||||
ListTile(
|
||||
title: Center(child: Text('根据朝向旋转定位图标')),
|
||||
onTap: () {
|
||||
AmapLocation.instance
|
||||
.listenLocation()
|
||||
.listen((it) =>
|
||||
_controller.setMyLocationRotateAngle(it.bearing!))
|
||||
.addTo(disposeBag);
|
||||
// AmapLocation.instance
|
||||
// .listenLocation()
|
||||
// .listen((it) =>
|
||||
// _controller.setMyLocationRotateAngle(it.bearing!))
|
||||
// .addTo(disposeBag);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Center(child: Text('行程动画')),
|
||||
onTap: () async {
|
||||
final result = await AmapSearch.instance.searchDriveRoute(
|
||||
from: LatLng(39.958245, 116.330929),
|
||||
to: LatLng(39.915599, 116.42912),
|
||||
);
|
||||
final pathList = await result.drivePathList;
|
||||
final stepList = [
|
||||
for (final path in pathList) ...await path.driveStepList
|
||||
];
|
||||
final coordinateList = [
|
||||
for (final step in stepList) ...await step.polyline
|
||||
];
|
||||
await _controller.addPlaybackTrace(
|
||||
coordinateList,
|
||||
iconProvider: _assetsIcon,
|
||||
duration: Duration(
|
||||
milliseconds: coordinateList.length * 500,
|
||||
),
|
||||
);
|
||||
for (int i = 0; i < coordinateList.length; i++) {
|
||||
final last = coordinateList[max(i - 1, 0)];
|
||||
final current = coordinateList[i];
|
||||
await _controller.setCameraPosition(
|
||||
coordinate: coordinateList[i],
|
||||
zoom: 18,
|
||||
tilt: 45,
|
||||
bearing: bearing(
|
||||
last.latitude,
|
||||
last.longitude,
|
||||
current.latitude,
|
||||
current.longitude,
|
||||
) -
|
||||
105,
|
||||
);
|
||||
await Future.delayed(Duration(milliseconds: 500));
|
||||
}
|
||||
// final result = await AmapSearch.instance.searchDriveRoute(
|
||||
// from: LatLng(39.958245, 116.330929),
|
||||
// to: LatLng(39.915599, 116.42912),
|
||||
// );
|
||||
// final pathList = await result.drivePathList;
|
||||
// final stepList = [
|
||||
// for (final path in pathList) ...await path.driveStepList
|
||||
// ];
|
||||
// final coordinateList = [
|
||||
// for (final step in stepList) ...await step.polyline
|
||||
// ];
|
||||
// await _controller.addPlaybackTrace(
|
||||
// coordinateList,
|
||||
// iconProvider: _assetsIcon,
|
||||
// duration: Duration(
|
||||
// milliseconds: coordinateList.length * 500,
|
||||
// ),
|
||||
// );
|
||||
// for (int i = 0; i < coordinateList.length; i++) {
|
||||
// final last = coordinateList[max(i - 1, 0)];
|
||||
// final current = coordinateList[i];
|
||||
// await _controller.setCameraPosition(
|
||||
// coordinate: coordinateList[i],
|
||||
// zoom: 18,
|
||||
// tilt: 45,
|
||||
// bearing: bearing(
|
||||
// last.latitude,
|
||||
// last.longitude,
|
||||
// current.latitude,
|
||||
// current.longitude,
|
||||
// ) -
|
||||
// 105,
|
||||
// );
|
||||
// await Future.delayed(Duration(milliseconds: 500));
|
||||
// }
|
||||
},
|
||||
),
|
||||
],
|
||||
@ -483,15 +483,15 @@ class _SecondScreen extends StatelessWidget {
|
||||
Flexible(child: AmapView()),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
AmapLocation.instance.listenLocation().listen((event) {
|
||||
print(event);
|
||||
});
|
||||
// AmapLocation.instance.listenLocation().listen((event) {
|
||||
// print(event);
|
||||
// });
|
||||
},
|
||||
child: Text('开始定位'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
AmapLocation.instance.stopLocation();
|
||||
// AmapLocation.instance.stopLocation();
|
||||
},
|
||||
child: Text('停止定位'),
|
||||
),
|
||||
|
@ -123,22 +123,22 @@ class _DrawPolylineScreenState extends State<DrawPolylineScreen>
|
||||
ListTile(
|
||||
title: Center(child: Text('添加回放轨迹')),
|
||||
onTap: () async {
|
||||
final result = await AmapSearch.instance.searchDriveRoute(
|
||||
from: LatLng(39.958245, 116.330929),
|
||||
to: LatLng(39.915599, 116.42912),
|
||||
);
|
||||
final pathList = await result.drivePathList;
|
||||
final stepList = [
|
||||
for (final path in pathList) ...await path.driveStepList
|
||||
];
|
||||
final coordinateList = [
|
||||
for (final step in stepList) ...await step.polyline
|
||||
];
|
||||
_playbackTrace = await _controller.addPlaybackTrace(
|
||||
coordinateList,
|
||||
iconProvider: _assetsIcon1,
|
||||
duration: Duration(seconds: 10),
|
||||
);
|
||||
// final result = await AmapSearch.instance.searchDriveRoute(
|
||||
// from: LatLng(39.958245, 116.330929),
|
||||
// to: LatLng(39.915599, 116.42912),
|
||||
// );
|
||||
// final pathList = await result.drivePathList;
|
||||
// final stepList = [
|
||||
// for (final path in pathList) ...await path.driveStepList
|
||||
// ];
|
||||
// final coordinateList = [
|
||||
// for (final step in stepList) ...await step.polyline
|
||||
// ];
|
||||
// _playbackTrace = await _controller.addPlaybackTrace(
|
||||
// coordinateList,
|
||||
// iconProvider: _assetsIcon1,
|
||||
// duration: Duration(seconds: 10),
|
||||
// );
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
|
@ -1,8 +1,8 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:amap_location_fluttify/amap_location_fluttify.dart';
|
||||
// import 'package:amap_location_fluttify/amap_location_fluttify.dart';
|
||||
import 'package:amap_map_fluttify/amap_map_fluttify.dart';
|
||||
import 'package:amap_search_fluttify/amap_search_fluttify.dart';
|
||||
// import 'package:amap_search_fluttify/amap_search_fluttify.dart';
|
||||
import 'package:decorated_flutter/decorated_flutter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
@ -49,18 +49,18 @@ class _GeoFenceScreenState extends State<GeoFenceScreen> {
|
||||
tilt: 90,
|
||||
);
|
||||
// 搜索poi
|
||||
final poiList =
|
||||
await AmapSearch.instance.searchAround(coordinate);
|
||||
await _controller.addMarkers([
|
||||
for (final poi in poiList)
|
||||
MarkerOption(
|
||||
coordinate: poi.latLng!,
|
||||
iconProvider: AssetImage('images/test_icon.png'),
|
||||
title: poi.title!,
|
||||
snippet: poi.address!,
|
||||
object: '自定义数据: ${poi.poiId}',
|
||||
)
|
||||
]);
|
||||
// final poiList =
|
||||
// await AmapSearch.instance.searchAround(coordinate);
|
||||
// await _controller.addMarkers([
|
||||
// for (final poi in poiList)
|
||||
// MarkerOption(
|
||||
// coordinate: poi.latLng!,
|
||||
// iconProvider: AssetImage('images/test_icon.png'),
|
||||
// title: poi.title!,
|
||||
// snippet: poi.address!,
|
||||
// object: '自定义数据: ${poi.poiId}',
|
||||
// )
|
||||
// ]);
|
||||
},
|
||||
),
|
||||
Positioned(
|
||||
@ -91,11 +91,11 @@ class _GeoFenceScreenState extends State<GeoFenceScreen> {
|
||||
_fencePolygon = await _controller.addPolygon(PolygonOption(
|
||||
coordinateList: _fenceCoordinateList,
|
||||
));
|
||||
AmapLocation.instance
|
||||
.addPolygonGeoFence(pointList: _fenceCoordinateList)
|
||||
.listen((event) {
|
||||
setState(() => _fenceState = '电子围栏事件: ${event.toString()}');
|
||||
});
|
||||
// AmapLocation.instance
|
||||
// .addPolygonGeoFence(pointList: _fenceCoordinateList)
|
||||
// .listen((event) {
|
||||
// setState(() => _fenceState = '电子围栏事件: ${event.toString()}');
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,19 +14,17 @@ const _indicator = 'images/indicator.png';
|
||||
double _fabHeight = 16.0;
|
||||
|
||||
typedef RequestPermission = Future<bool> Function();
|
||||
typedef PoiItemBuilder = Widget Function(Poi poi, bool selected);
|
||||
// typedef PoiItemBuilder = Widget Function(Poi poi, bool selected);
|
||||
|
||||
class LocationPicker extends StatefulWidget {
|
||||
const LocationPicker({
|
||||
required Key key,
|
||||
required this.requestPermission,
|
||||
required this.poiItemBuilder,
|
||||
this.zoomLevel = 16.0,
|
||||
this.zoomGesturesEnabled = false,
|
||||
this.showZoomControl = false,
|
||||
required this.centerIndicator,
|
||||
this.enableLoadMore = true,
|
||||
required this.onItemSelected,
|
||||
}) : assert(zoomLevel >= 3 && zoomLevel <= 19),
|
||||
super(key: key);
|
||||
|
||||
@ -34,7 +32,7 @@ class LocationPicker extends StatefulWidget {
|
||||
final RequestPermission requestPermission;
|
||||
|
||||
/// Poi列表项Builder
|
||||
final PoiItemBuilder poiItemBuilder;
|
||||
// final PoiItemBuilder poiItemBuilder;
|
||||
|
||||
/// 显示的缩放登记
|
||||
final double zoomLevel;
|
||||
@ -52,7 +50,7 @@ class LocationPicker extends StatefulWidget {
|
||||
final bool enableLoadMore;
|
||||
|
||||
/// 选中回调
|
||||
final ValueChanged<PoiInfo> onItemSelected;
|
||||
// final ValueChanged<PoiInfo> onItemSelected;
|
||||
|
||||
@override
|
||||
_LocationPickerState createState() => _LocationPickerState();
|
||||
@ -68,7 +66,7 @@ class _LocationPickerState extends State<LocationPicker>
|
||||
bool _moveByUser = true;
|
||||
|
||||
// 当前请求到的poi列表
|
||||
List<PoiInfo> _poiInfoList = [];
|
||||
// List<PoiInfo> _poiInfoList = [];
|
||||
|
||||
// 当前地图中心点
|
||||
late LatLng _currentCenterCoordinate;
|
||||
@ -172,57 +170,76 @@ class _LocationPickerState extends State<LocationPicker>
|
||||
],
|
||||
),
|
||||
panelBuilder: (scrollController) {
|
||||
return StreamBuilder<List<PoiInfo>>(
|
||||
stream: _poiStream.stream,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
final data = snapshot.data;
|
||||
return EasyRefresh(
|
||||
footer: MaterialFooter(),
|
||||
onLoad: widget.enableLoadMore ? _handleLoadMore : null,
|
||||
child: ListView.builder(
|
||||
padding: EdgeInsets.zero,
|
||||
controller: scrollController,
|
||||
shrinkWrap: true,
|
||||
itemCount: data!.length,
|
||||
itemBuilder: (context, index) {
|
||||
final poi = data[index].poi;
|
||||
final selected = data[index].selected;
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
// 遍历数据列表, 设置当前被选中的数据项
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
data[i].selected = i == index;
|
||||
}
|
||||
// 如果索引是0, 说明是当前位置, 更新这个数据
|
||||
_onMyLocation.add(index == 0);
|
||||
// 刷新数据
|
||||
_poiStream.add(data);
|
||||
// 设置地图中心点
|
||||
_setCenterCoordinate(poi.latLng!);
|
||||
// 回调
|
||||
widget.onItemSelected(data[index]);
|
||||
},
|
||||
child: widget.poiItemBuilder(poi, selected),
|
||||
);
|
||||
},
|
||||
return Container(
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
'附近位置',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return Center(child: CircularProgressIndicator());
|
||||
}
|
||||
},
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
// Expanded(
|
||||
// child: _buildPoiList(scrollController),
|
||||
// ),
|
||||
],
|
||||
),
|
||||
);
|
||||
// return StreamBuilder<List<PoiInfo>>(
|
||||
// stream: _poiStream.stream,
|
||||
// builder: (context, snapshot) {
|
||||
// if (snapshot.hasData) {
|
||||
// final data = snapshot.data;
|
||||
// return EasyRefresh(
|
||||
// footer: MaterialFooter(),
|
||||
// onLoad: widget.enableLoadMore ? _handleLoadMore : null,
|
||||
// child: ListView.builder(
|
||||
// padding: EdgeInsets.zero,
|
||||
// controller: scrollController,
|
||||
// shrinkWrap: true,
|
||||
// itemCount: data!.length,
|
||||
// itemBuilder: (context, index) {
|
||||
// final poi = data[index].poi;
|
||||
// final selected = data[index].selected;
|
||||
// return GestureDetector(
|
||||
// onTap: () {
|
||||
// // 遍历数据列表, 设置当前被选中的数据项
|
||||
// for (int i = 0; i < data.length; i++) {
|
||||
// data[i].selected = i == index;
|
||||
// }
|
||||
// // 如果索引是0, 说明是当前位置, 更新这个数据
|
||||
// _onMyLocation.add(index == 0);
|
||||
// // 刷新数据
|
||||
// _poiStream.add(data);
|
||||
// // 设置地图中心点
|
||||
// _setCenterCoordinate(poi.latLng!);
|
||||
// // 回调
|
||||
// widget.onItemSelected(data[index]);
|
||||
// },
|
||||
// // child: widget.poiItemBuilder(poi, selected),
|
||||
// );
|
||||
// },
|
||||
// ),
|
||||
// );
|
||||
// } else {
|
||||
// return Center(child: CircularProgressIndicator());
|
||||
// }
|
||||
// },
|
||||
// );
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _search(LatLng location) async {
|
||||
final poiList = await AmapSearch.instance.searchAround(location);
|
||||
_poiInfoList = poiList.map((poi) => PoiInfo(poi)).toList();
|
||||
// final poiList = await AmapSearch.instance.searchAround(location);
|
||||
// _poiInfoList = poiList.map((poi) => PoiInfo(poi)).toList();
|
||||
// 默认勾选第一项
|
||||
if (_poiInfoList.isNotEmpty) _poiInfoList[0].selected = true;
|
||||
_poiStream.add(_poiInfoList);
|
||||
// if (_poiInfoList.isNotEmpty) _poiInfoList[0].selected = true;
|
||||
// _poiStream.add(_poiInfoList);
|
||||
|
||||
// 重置页数
|
||||
_page = 1;
|
||||
@ -242,25 +259,24 @@ class _LocationPickerState extends State<LocationPicker>
|
||||
}
|
||||
|
||||
Future<void> _handleLoadMore() async {
|
||||
final poiList = await AmapSearch.instance.searchAround(
|
||||
_currentCenterCoordinate,
|
||||
page: ++_page,
|
||||
);
|
||||
_poiInfoList.addAll(poiList.map((poi) => PoiInfo(poi)).toList());
|
||||
_poiStream.add(_poiInfoList);
|
||||
// final poiList = await AmapSearch.instance.searchAround(
|
||||
// _currentCenterCoordinate,
|
||||
// page: ++_page,
|
||||
// );
|
||||
// _poiInfoList.addAll(poiList.map((poi) => PoiInfo(poi)).toList());
|
||||
// _poiStream.add(_poiInfoList);
|
||||
}
|
||||
}
|
||||
|
||||
mixin _BLoCMixin on State<LocationPicker> {
|
||||
// poi流
|
||||
final _poiStream = StreamController<List<PoiInfo>>();
|
||||
// final _poiStream = StreamController<List<PoiInfo>>();
|
||||
|
||||
// 是否在我的位置
|
||||
final _onMyLocation = StreamController<bool>();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_poiStream.close();
|
||||
_onMyLocation.close();
|
||||
super.dispose();
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
import 'package:amap_search_fluttify/amap_search_fluttify.dart';
|
||||
|
||||
class PoiInfo {
|
||||
PoiInfo(this.poi);
|
||||
|
||||
final Poi poi;
|
||||
bool selected = false;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'PoiInfo{poi: $poi, selected: $selected}';
|
||||
}
|
||||
}
|
||||
// import 'package:amap_search_fluttify/amap_search_fluttify.dart';
|
||||
//
|
||||
// class PoiInfo {
|
||||
// PoiInfo(this.poi);
|
||||
//
|
||||
// final Poi poi;
|
||||
// bool selected = false;
|
||||
//
|
||||
// @override
|
||||
// String toString() {
|
||||
// return 'PoiInfo{poi: $poi, selected: $selected}';
|
||||
// }
|
||||
// }
|
||||
|
Reference in New Issue
Block a user