reason

百度定位逻辑

...@@ -110,11 +110,12 @@ class PoemPublishState extends State<PoemPublish> { ...@@ -110,11 +110,12 @@ 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 BMFPoiInfo model = result as BMFPoiInfo; 113 + final BMFSuggestionInfo model =
114 - _longitude = model.pt!.longitude.toString(); 114 + result as BMFSuggestionInfo;
115 - _latitude = model.pt!.latitude.toString(); 115 + _longitude = model.location!.longitude.toString();
116 + _latitude = model.location!.latitude.toString();
116 _address = 117 _address =
117 - '${model.province!} ${model.city!} ${model.area!} ${model.name!}'; 118 + '${model.city!} ${model.district!} ${model.address!}';
118 }); 119 });
119 }); 120 });
120 }, 121 },
......
...@@ -20,7 +20,7 @@ class AddressSelectPage extends StatefulWidget { ...@@ -20,7 +20,7 @@ class AddressSelectPage extends StatefulWidget {
20 } 20 }
21 21
22 class AddressSelectPageState extends State<AddressSelectPage> { 22 class AddressSelectPageState extends State<AddressSelectPage> {
23 - List<BMFPoiInfo> _list = []; 23 + List<BMFSuggestionInfo> _list = [];
24 int _index = 0; 24 int _index = 0;
25 final ScrollController _controller = ScrollController(); 25 final ScrollController _controller = ScrollController();
26 late BMFMapController _myMapController; 26 late BMFMapController _myMapController;
...@@ -65,8 +65,6 @@ class AddressSelectPageState extends State<AddressSelectPage> { ...@@ -65,8 +65,6 @@ class AddressSelectPageState extends State<AddressSelectPage> {
65 }); 65 });
66 } 66 }
67 67
68 - isLoading = true;
69 -
70 ///设置定位参数 68 ///设置定位参数
71 _locationAction(); 69 _locationAction();
72 _startLocation(); 70 _startLocation();
...@@ -99,20 +97,26 @@ class AddressSelectPageState extends State<AddressSelectPage> { ...@@ -99,20 +97,26 @@ class AddressSelectPageState extends State<AddressSelectPage> {
99 false); 97 false);
100 98
101 // 构造检索参数 99 // 构造检索参数
102 - BMFPoiNearbySearchOption poiNearbySearchOption = BMFPoiNearbySearchOption( 100 + BMFSuggestionSearchOption suggestionSearchOption =
103 - keywords: <String>['小吃', '学校', '酒店', '公司', '住宅'], 101 + BMFSuggestionSearchOption(
104 - location: BMFCoordinate( 102 + keyword: '街道',
105 - _locationResult.latitude!, _locationResult.longitude!), 103 + cityname: _locationResult.city,
106 - radius: 1000, 104 + location:
107 - isRadiusLimit: true); 105 + BMFCoordinate(_locationResult.latitude!, _locationResult.longitude!),
108 - BMFPoiNearbySearch nearbySearch = BMFPoiNearbySearch(); 106 + cityLimit: true,
109 - nearbySearch.onGetPoiNearbySearchResult( 107 + );
110 - callback: (BMFPoiSearchResult result, BMFSearchErrorCode errorCode) { 108 + BMFSuggestionSearch suggestionSearch = BMFSuggestionSearch();
111 - _list = result.poiInfoList!; 109 + suggestionSearch.onGetSuggestSearchResult(callback:
110 + (BMFSuggestionSearchResult result, BMFSearchErrorCode errorCode) {
111 + print("sug检索回调 result = ${result.toMap()} \n errorCode = ${errorCode}");
112 + _list = result.suggestionList!;
113 + if (_list.isEmpty) {
114 + Toast.show("暂时无法搜索到该位置!");
115 + }
116 + isLoading = false;
112 setState(() {}); 117 setState(() {});
113 }); 118 });
114 - bool flag = await nearbySearch.poiNearbySearch(poiNearbySearchOption); 119 + bool flag = await suggestionSearch.suggestionSearch(suggestionSearchOption);
115 - isLoading = false;
116 } 120 }
117 121
118 /// 设置地图参数 122 /// 设置地图参数
...@@ -141,6 +145,7 @@ class AddressSelectPageState extends State<AddressSelectPage> { ...@@ -141,6 +145,7 @@ class AddressSelectPageState extends State<AddressSelectPage> {
141 145
142 /// 启动定位 146 /// 启动定位
143 Future<void> _startLocation() async { 147 Future<void> _startLocation() async {
148 + isLoading = true;
144 if (Platform.isIOS) { 149 if (Platform.isIOS) {
145 await myLocPlugin 150 await myLocPlugin
146 .singleLocation({'isReGeocode': true, 'isNetworkState': true}); 151 .singleLocation({'isReGeocode': true, 'isNetworkState': true});
...@@ -173,27 +178,33 @@ class AddressSelectPageState extends State<AddressSelectPage> { ...@@ -173,27 +178,33 @@ class AddressSelectPageState extends State<AddressSelectPage> {
173 appBar: SearchBar( 178 appBar: SearchBar(
174 hintText: '搜索地址', 179 hintText: '搜索地址',
175 onPressed: (text) async { 180 onPressed: (text) async {
181 + isLoading = true;
176 _controller.animateTo(0.0, 182 _controller.animateTo(0.0,
177 duration: const Duration(milliseconds: 10), curve: Curves.ease); 183 duration: const Duration(milliseconds: 10), curve: Curves.ease);
178 _index = 0; 184 _index = 0;
179 // 构造检索参数 185 // 构造检索参数
180 - BMFPoiNearbySearchOption poiNearbySearchOption = 186 + BMFSuggestionSearchOption suggestionSearchOption =
181 - BMFPoiNearbySearchOption( 187 + BMFSuggestionSearchOption(
182 - keywords: <String>[text], 188 + keyword: text,
189 + cityname: _locationResult.city,
183 location: BMFCoordinate( 190 location: BMFCoordinate(
184 _locationResult.latitude!, _locationResult.longitude!), 191 _locationResult.latitude!, _locationResult.longitude!),
185 - radius: 1000, 192 + cityLimit: true,
186 - isRadiusLimit: true); 193 + );
187 - BMFPoiNearbySearch nearbySearch = BMFPoiNearbySearch(); 194 + BMFSuggestionSearch suggestionSearch = BMFSuggestionSearch();
188 - nearbySearch.onGetPoiNearbySearchResult(callback: 195 + suggestionSearch.onGetSuggestSearchResult(callback:
189 - (BMFPoiSearchResult result, BMFSearchErrorCode errorCode) { 196 + (BMFSuggestionSearchResult result, BMFSearchErrorCode errorCode) {
190 - _list = result.poiInfoList!; 197 + print(
198 + "sug检索回调 result = ${result.toMap()} \n errorCode = ${errorCode}");
199 + _list = result.suggestionList!;
191 if (_list.isEmpty) { 200 if (_list.isEmpty) {
192 Toast.show("暂时无法搜索到该位置!"); 201 Toast.show("暂时无法搜索到该位置!");
193 } 202 }
203 + isLoading = false;
194 setState(() {}); 204 setState(() {});
195 }); 205 });
196 - bool flag = await nearbySearch.poiNearbySearch(poiNearbySearchOption); 206 + bool flag =
207 + await suggestionSearch.suggestionSearch(suggestionSearchOption);
197 }, 208 },
198 ), 209 ),
199 body: SafeArea( 210 body: SafeArea(
...@@ -223,14 +234,15 @@ class AddressSelectPageState extends State<AddressSelectPage> { ...@@ -223,14 +234,15 @@ class AddressSelectPageState extends State<AddressSelectPage> {
223 onTap: () { 234 onTap: () {
224 _index = index; 235 _index = index;
225 _myMapController.updateMapOptions(BMFMapOptions( 236 _myMapController.updateMapOptions(BMFMapOptions(
226 - center: BMFCoordinate(_list[index].pt!.latitude, 237 + center: BMFCoordinate(
227 - _list[index].pt!.longitude))); 238 + _list[index].location!.latitude,
239 + _list[index].location!.longitude)));
228 240
229 /// 创建BMFMarker 241 /// 创建BMFMarker
230 BMFMarker marker = BMFMarker.icon( 242 BMFMarker marker = BMFMarker.icon(
231 position: BMFCoordinate( 243 position: BMFCoordinate(
232 - _list[index].pt!.latitude, 244 + _list[index].location!.latitude,
233 - _list[index].pt!.longitude), 245 + _list[index].location!.longitude),
234 title: 'flutterMaker', 246 title: 'flutterMaker',
235 identifier: 'flutter_marker', 247 identifier: 'flutter_marker',
236 icon: 'assets/images/map/icon_mark.png'); 248 icon: 'assets/images/map/icon_mark.png');
...@@ -240,8 +252,8 @@ class AddressSelectPageState extends State<AddressSelectPage> { ...@@ -240,8 +252,8 @@ class AddressSelectPageState extends State<AddressSelectPage> {
240 252
241 ///设置中心点 253 ///设置中心点
242 _myMapController.setCenterCoordinate( 254 _myMapController.setCenterCoordinate(
243 - BMFCoordinate(_list[index].pt!.latitude, 255 + BMFCoordinate(_list[index].location!.latitude,
244 - _list[index].pt!.longitude), 256 + _list[index].location!.longitude),
245 false); 257 false);
246 258
247 setState(() {}); 259 setState(() {});
...@@ -275,7 +287,7 @@ class _AddressItem extends StatelessWidget { ...@@ -275,7 +287,7 @@ class _AddressItem extends StatelessWidget {
275 this.onTap, 287 this.onTap,
276 }) : super(key: key); 288 }) : super(key: key);
277 289
278 - final BMFPoiInfo poi; 290 + final BMFSuggestionInfo poi;
279 final bool isSelected; 291 final bool isSelected;
280 final GestureTapCallback? onTap; 292 final GestureTapCallback? onTap;
281 293
...@@ -291,7 +303,7 @@ class _AddressItem extends StatelessWidget { ...@@ -291,7 +303,7 @@ class _AddressItem extends StatelessWidget {
291 children: <Widget>[ 303 children: <Widget>[
292 Expanded( 304 Expanded(
293 child: Text( 305 child: Text(
294 - '${poi.province} ${poi.city} ${poi.area} ${poi.name}', 306 + '${poi.city} ${poi.district} ${poi.address}',
295 ), 307 ),
296 ), 308 ),
297 Visibility( 309 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+11 18 +version: 1.0.0+12
19 19
20 environment: 20 environment:
21 sdk: ">=2.16.2 <3.0.0" 21 sdk: ">=2.16.2 <3.0.0"
......