reason

百度定位逻辑

...@@ -13,10 +13,10 @@ import 'package:Parlando/routers/routers.dart'; ...@@ -13,10 +13,10 @@ import 'package:Parlando/routers/routers.dart';
13 import 'package:Parlando/widgets/my_app_bar.dart'; 13 import 'package:Parlando/widgets/my_app_bar.dart';
14 14
15 import 'package:Parlando/extension/int_extension.dart'; 15 import 'package:Parlando/extension/int_extension.dart';
16 +import 'package:flutter_baidu_mapapi_search/flutter_baidu_mapapi_search.dart';
16 import 'package:getwidget/getwidget.dart'; 17 import 'package:getwidget/getwidget.dart';
17 import 'package:path_provider/path_provider.dart'; 18 import 'package:path_provider/path_provider.dart';
18 19
19 -import '../../map/poi_search_model.dart';
20 import '../poem_router.dart'; 20 import '../poem_router.dart';
21 21
22 class PoemPublish extends StatefulWidget { 22 class PoemPublish extends StatefulWidget {
...@@ -110,11 +110,11 @@ class PoemPublishState extends State<PoemPublish> { ...@@ -110,11 +110,11 @@ class PoemPublishState extends State<PoemPublish> {
110 NavigatorUtils.pushResult( 110 NavigatorUtils.pushResult(
111 context, PoemRouter.addressSelectPage, (result) { 111 context, PoemRouter.addressSelectPage, (result) {
112 setState(() { 112 setState(() {
113 - final PoiSearch model = result as PoiSearch; 113 + final BMFPoiInfo model = result as BMFPoiInfo;
114 - _longitude = model.longitude!; 114 + _longitude = model.pt!.longitude.toString();
115 - _latitude = model.latitude!; 115 + _latitude = model.pt!.latitude.toString();
116 _address = 116 _address =
117 - '${model.provinceName!} ${model.cityName!} ${model.adName!} ${model.title!}'; 117 + '${model.province!} ${model.city!} ${model.area!} ${model.name!}';
118 }); 118 });
119 }); 119 });
120 }, 120 },
......
1 import 'dart:io'; 1 import 'dart:io';
2 2
3 import 'package:flutter/material.dart'; 3 import 'package:flutter/material.dart';
4 -import 'package:Parlando/routers/fluro_navigator.dart';
5 -import 'package:Parlando/util/toast_utils.dart';
6 import 'package:Parlando/widgets/my_button.dart'; 4 import 'package:Parlando/widgets/my_button.dart';
7 import 'package:Parlando/widgets/search_bar.dart'; 5 import 'package:Parlando/widgets/search_bar.dart';
8 import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; 6 import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart';
9 import 'package:flutter_baidu_mapapi_map/flutter_baidu_mapapi_map.dart'; 7 import 'package:flutter_baidu_mapapi_map/flutter_baidu_mapapi_map.dart';
8 +import 'package:flutter_baidu_mapapi_search/flutter_baidu_mapapi_search.dart';
10 import 'package:flutter_bmflocation/flutter_bmflocation.dart'; 9 import 'package:flutter_bmflocation/flutter_bmflocation.dart';
11 -import '../../map/interface/amap_2d_controller.dart'; 10 +import 'package:getwidget/getwidget.dart';
12 -import '../../map/poi_search_model.dart'; 11 +
12 +import '../../routers/fluro_navigator.dart';
13 +import '../../util/toast_utils.dart';
13 14
14 class AddressSelectPage extends StatefulWidget { 15 class AddressSelectPage extends StatefulWidget {
15 const AddressSelectPage({Key? key}) : super(key: key); 16 const AddressSelectPage({Key? key}) : super(key: key);
...@@ -19,13 +20,13 @@ class AddressSelectPage extends StatefulWidget { ...@@ -19,13 +20,13 @@ class AddressSelectPage extends StatefulWidget {
19 } 20 }
20 21
21 class AddressSelectPageState extends State<AddressSelectPage> { 22 class AddressSelectPageState extends State<AddressSelectPage> {
22 - List<PoiSearch> _list = []; 23 + List<BMFPoiInfo> _list = [];
23 int _index = 0; 24 int _index = 0;
24 final ScrollController _controller = ScrollController(); 25 final ScrollController _controller = ScrollController();
25 - AMap2DController? _aMap2DController;
26 late BMFMapController _myMapController; 26 late BMFMapController _myMapController;
27 - BaiduLocation _loationResult = BaiduLocation(); 27 + BaiduLocation _locationResult = BaiduLocation();
28 LocationFlutterPlugin myLocPlugin = LocationFlutterPlugin(); 28 LocationFlutterPlugin myLocPlugin = LocationFlutterPlugin();
29 + bool isLoading = false;
29 30
30 @override 31 @override
31 void dispose() { 32 void dispose() {
...@@ -46,7 +47,7 @@ class AddressSelectPageState extends State<AddressSelectPage> { ...@@ -46,7 +47,7 @@ class AddressSelectPageState extends State<AddressSelectPage> {
46 ///接受定位回调 47 ///接受定位回调
47 myLocPlugin.singleLocationCallback(callback: (BaiduLocation result) { 48 myLocPlugin.singleLocationCallback(callback: (BaiduLocation result) {
48 setState(() { 49 setState(() {
49 - _loationResult = result; 50 + _locationResult = result;
50 locationFinish(); 51 locationFinish();
51 }); 52 });
52 }); 53 });
...@@ -56,7 +57,7 @@ class AddressSelectPageState extends State<AddressSelectPage> { ...@@ -56,7 +57,7 @@ class AddressSelectPageState extends State<AddressSelectPage> {
56 BMFMapSDK.setCoordType(BMF_COORD_TYPE.BD09LL); 57 BMFMapSDK.setCoordType(BMF_COORD_TYPE.BD09LL);
57 myLocPlugin.seriesLocationCallback(callback: (BaiduLocation result) { 58 myLocPlugin.seriesLocationCallback(callback: (BaiduLocation result) {
58 setState(() { 59 setState(() {
59 - _loationResult = result; 60 + _locationResult = result;
60 61
61 locationFinish(); 62 locationFinish();
62 myLocPlugin.stopLocation(); 63 myLocPlugin.stopLocation();
...@@ -64,6 +65,8 @@ class AddressSelectPageState extends State<AddressSelectPage> { ...@@ -64,6 +65,8 @@ class AddressSelectPageState extends State<AddressSelectPage> {
64 }); 65 });
65 } 66 }
66 67
68 + isLoading = true;
69 +
67 ///设置定位参数 70 ///设置定位参数
68 _locationAction(); 71 _locationAction();
69 _startLocation(); 72 _startLocation();
...@@ -77,16 +80,14 @@ class AddressSelectPageState extends State<AddressSelectPage> { ...@@ -77,16 +80,14 @@ class AddressSelectPageState extends State<AddressSelectPage> {
77 } 80 }
78 81
79 ///定位完成添加mark 82 ///定位完成添加mark
80 - void locationFinish() { 83 + Future<void> locationFinish() async {
81 /// 创建BMFMarker 84 /// 创建BMFMarker
82 BMFMarker marker = BMFMarker.icon( 85 BMFMarker marker = BMFMarker.icon(
83 position: BMFCoordinate( 86 position: BMFCoordinate(
84 - _loationResult.latitude ?? 0.0, _loationResult.longitude ?? 0.0), 87 + _locationResult.latitude ?? 0.0, _locationResult.longitude ?? 0.0),
85 title: 'flutterMaker', 88 title: 'flutterMaker',
86 identifier: 'flutter_marker', 89 identifier: 'flutter_marker',
87 icon: 'assets/images/map/icon_mark.png'); 90 icon: 'assets/images/map/icon_mark.png');
88 - print(_loationResult.latitude.toString() +
89 - _loationResult.longitude.toString());
90 91
91 /// 添加Marker 92 /// 添加Marker
92 _myMapController.addMarker(marker); 93 _myMapController.addMarker(marker);
...@@ -94,8 +95,24 @@ class AddressSelectPageState extends State<AddressSelectPage> { ...@@ -94,8 +95,24 @@ class AddressSelectPageState extends State<AddressSelectPage> {
94 ///设置中心点 95 ///设置中心点
95 _myMapController.setCenterCoordinate( 96 _myMapController.setCenterCoordinate(
96 BMFCoordinate( 97 BMFCoordinate(
97 - _loationResult.latitude ?? 0.0, _loationResult.longitude ?? 0.0), 98 + _locationResult.latitude ?? 0.0, _locationResult.longitude ?? 0.0),
98 false); 99 false);
100 +
101 + // 构造检索参数
102 + BMFPoiNearbySearchOption poiNearbySearchOption = BMFPoiNearbySearchOption(
103 + keywords: <String>['小吃', '学校', '酒店', '公司', '住宅'],
104 + location: BMFCoordinate(
105 + _locationResult.latitude!, _locationResult.longitude!),
106 + radius: 1000,
107 + isRadiusLimit: true);
108 + BMFPoiNearbySearch nearbySearch = BMFPoiNearbySearch();
109 + nearbySearch.onGetPoiNearbySearchResult(
110 + callback: (BMFPoiSearchResult result, BMFSearchErrorCode errorCode) {
111 + _list = result.poiInfoList!;
112 + setState(() {});
113 + });
114 + bool flag = await nearbySearch.poiNearbySearch(poiNearbySearchOption);
115 + isLoading = false;
99 } 116 }
100 117
101 /// 设置地图参数 118 /// 设置地图参数
...@@ -155,11 +172,28 @@ class AddressSelectPageState extends State<AddressSelectPage> { ...@@ -155,11 +172,28 @@ class AddressSelectPageState extends State<AddressSelectPage> {
155 resizeToAvoidBottomInset: false, 172 resizeToAvoidBottomInset: false,
156 appBar: SearchBar( 173 appBar: SearchBar(
157 hintText: '搜索地址', 174 hintText: '搜索地址',
158 - onPressed: (text) { 175 + onPressed: (text) async {
159 _controller.animateTo(0.0, 176 _controller.animateTo(0.0,
160 duration: const Duration(milliseconds: 10), curve: Curves.ease); 177 duration: const Duration(milliseconds: 10), curve: Curves.ease);
161 _index = 0; 178 _index = 0;
162 - _aMap2DController?.search(text); 179 + // 构造检索参数
180 + BMFPoiNearbySearchOption poiNearbySearchOption =
181 + BMFPoiNearbySearchOption(
182 + keywords: <String>[text],
183 + location: BMFCoordinate(
184 + _locationResult.latitude!, _locationResult.longitude!),
185 + radius: 1000,
186 + isRadiusLimit: true);
187 + BMFPoiNearbySearch nearbySearch = BMFPoiNearbySearch();
188 + nearbySearch.onGetPoiNearbySearchResult(callback:
189 + (BMFPoiSearchResult result, BMFSearchErrorCode errorCode) {
190 + _list = result.poiInfoList!;
191 + if (_list.isEmpty) {
192 + Toast.show("暂时无法搜索到该位置!");
193 + }
194 + setState(() {});
195 + });
196 + bool flag = await nearbySearch.poiNearbySearch(poiNearbySearchOption);
163 }, 197 },
164 ), 198 ),
165 body: SafeArea( 199 body: SafeArea(
...@@ -176,18 +210,40 @@ class AddressSelectPageState extends State<AddressSelectPage> { ...@@ -176,18 +210,40 @@ class AddressSelectPageState extends State<AddressSelectPage> {
176 ), 210 ),
177 Expanded( 211 Expanded(
178 flex: 11, 212 flex: 11,
179 - child: ListView.separated( 213 + child: isLoading
214 + ? const GFLoader()
215 + : ListView.separated(
180 controller: _controller, 216 controller: _controller,
181 itemCount: _list.length, 217 itemCount: _list.length,
182 separatorBuilder: (_, index) => const Divider(), 218 separatorBuilder: (_, index) => const Divider(),
183 itemBuilder: (_, index) { 219 itemBuilder: (_, index) {
184 return _AddressItem( 220 return _AddressItem(
185 isSelected: _index == index, 221 isSelected: _index == index,
186 - date: _list[index], 222 + poi: _list[index],
187 onTap: () { 223 onTap: () {
188 _index = index; 224 _index = index;
189 - _aMap2DController?.move( 225 + _myMapController.updateMapOptions(BMFMapOptions(
190 - _list[index].latitude!, _list[index].longitude!); 226 + center: BMFCoordinate(_list[index].pt!.latitude,
227 + _list[index].pt!.longitude)));
228 +
229 + /// 创建BMFMarker
230 + BMFMarker marker = BMFMarker.icon(
231 + position: BMFCoordinate(
232 + _list[index].pt!.latitude,
233 + _list[index].pt!.longitude),
234 + title: 'flutterMaker',
235 + identifier: 'flutter_marker',
236 + icon: 'assets/images/map/icon_mark.png');
237 +
238 + /// 添加Marker
239 + _myMapController.addMarker(marker);
240 +
241 + ///设置中心点
242 + _myMapController.setCenterCoordinate(
243 + BMFCoordinate(_list[index].pt!.latitude,
244 + _list[index].pt!.longitude),
245 + false);
246 +
191 setState(() {}); 247 setState(() {});
192 }, 248 },
193 ); 249 );
...@@ -214,12 +270,12 @@ class AddressSelectPageState extends State<AddressSelectPage> { ...@@ -214,12 +270,12 @@ class AddressSelectPageState extends State<AddressSelectPage> {
214 class _AddressItem extends StatelessWidget { 270 class _AddressItem extends StatelessWidget {
215 const _AddressItem({ 271 const _AddressItem({
216 Key? key, 272 Key? key,
217 - required this.date, 273 + required this.poi,
218 this.isSelected = false, 274 this.isSelected = false,
219 this.onTap, 275 this.onTap,
220 }) : super(key: key); 276 }) : super(key: key);
221 277
222 - final PoiSearch date; 278 + final BMFPoiInfo poi;
223 final bool isSelected; 279 final bool isSelected;
224 final GestureTapCallback? onTap; 280 final GestureTapCallback? onTap;
225 281
...@@ -235,7 +291,7 @@ class _AddressItem extends StatelessWidget { ...@@ -235,7 +291,7 @@ class _AddressItem extends StatelessWidget {
235 children: <Widget>[ 291 children: <Widget>[
236 Expanded( 292 Expanded(
237 child: Text( 293 child: Text(
238 - '${date.provinceName!} ${date.cityName!} ${date.adName!} ${date.title!}', 294 + '${poi.province} ${poi.city} ${poi.area} ${poi.name}',
239 ), 295 ),
240 ), 296 ),
241 Visibility( 297 Visibility(
......
...@@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev ...@@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
15 # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. 15 # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
16 # Read more about iOS versioning at 16 # Read more about iOS versioning at
17 # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html 17 # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
18 -version: 1.0.0+10 18 +version: 1.0.0+11
19 19
20 environment: 20 environment:
21 sdk: ">=2.16.2 <3.0.0" 21 sdk: ">=2.16.2 <3.0.0"
......