reason

百度定位逻辑

......@@ -110,11 +110,12 @@ class PoemPublishState extends State<PoemPublish> {
NavigatorUtils.pushResult(
context, PoemRouter.addressSelectPage, (result) {
setState(() {
final BMFPoiInfo model = result as BMFPoiInfo;
_longitude = model.pt!.longitude.toString();
_latitude = model.pt!.latitude.toString();
final BMFSuggestionInfo model =
result as BMFSuggestionInfo;
_longitude = model.location!.longitude.toString();
_latitude = model.location!.latitude.toString();
_address =
'${model.province!} ${model.city!} ${model.area!} ${model.name!}';
'${model.city!} ${model.district!} ${model.address!}';
});
});
},
......
......@@ -20,7 +20,7 @@ class AddressSelectPage extends StatefulWidget {
}
class AddressSelectPageState extends State<AddressSelectPage> {
List<BMFPoiInfo> _list = [];
List<BMFSuggestionInfo> _list = [];
int _index = 0;
final ScrollController _controller = ScrollController();
late BMFMapController _myMapController;
......@@ -65,8 +65,6 @@ class AddressSelectPageState extends State<AddressSelectPage> {
});
}
isLoading = true;
///设置定位参数
_locationAction();
_startLocation();
......@@ -99,20 +97,26 @@ class AddressSelectPageState extends State<AddressSelectPage> {
false);
// 构造检索参数
BMFPoiNearbySearchOption poiNearbySearchOption = BMFPoiNearbySearchOption(
keywords: <String>['小吃', '学校', '酒店', '公司', '住宅'],
location: BMFCoordinate(
_locationResult.latitude!, _locationResult.longitude!),
radius: 1000,
isRadiusLimit: true);
BMFPoiNearbySearch nearbySearch = BMFPoiNearbySearch();
nearbySearch.onGetPoiNearbySearchResult(
callback: (BMFPoiSearchResult result, BMFSearchErrorCode errorCode) {
_list = result.poiInfoList!;
BMFSuggestionSearchOption suggestionSearchOption =
BMFSuggestionSearchOption(
keyword: '街道',
cityname: _locationResult.city,
location:
BMFCoordinate(_locationResult.latitude!, _locationResult.longitude!),
cityLimit: true,
);
BMFSuggestionSearch suggestionSearch = BMFSuggestionSearch();
suggestionSearch.onGetSuggestSearchResult(callback:
(BMFSuggestionSearchResult result, BMFSearchErrorCode errorCode) {
print("sug检索回调 result = ${result.toMap()} \n errorCode = ${errorCode}");
_list = result.suggestionList!;
if (_list.isEmpty) {
Toast.show("暂时无法搜索到该位置!");
}
isLoading = false;
setState(() {});
});
bool flag = await nearbySearch.poiNearbySearch(poiNearbySearchOption);
isLoading = false;
bool flag = await suggestionSearch.suggestionSearch(suggestionSearchOption);
}
/// 设置地图参数
......@@ -141,6 +145,7 @@ class AddressSelectPageState extends State<AddressSelectPage> {
/// 启动定位
Future<void> _startLocation() async {
isLoading = true;
if (Platform.isIOS) {
await myLocPlugin
.singleLocation({'isReGeocode': true, 'isNetworkState': true});
......@@ -173,27 +178,33 @@ class AddressSelectPageState extends State<AddressSelectPage> {
appBar: SearchBar(
hintText: '搜索地址',
onPressed: (text) async {
isLoading = true;
_controller.animateTo(0.0,
duration: const Duration(milliseconds: 10), curve: Curves.ease);
_index = 0;
// 构造检索参数
BMFPoiNearbySearchOption poiNearbySearchOption =
BMFPoiNearbySearchOption(
keywords: <String>[text],
location: BMFCoordinate(
_locationResult.latitude!, _locationResult.longitude!),
radius: 1000,
isRadiusLimit: true);
BMFPoiNearbySearch nearbySearch = BMFPoiNearbySearch();
nearbySearch.onGetPoiNearbySearchResult(callback:
(BMFPoiSearchResult result, BMFSearchErrorCode errorCode) {
_list = result.poiInfoList!;
BMFSuggestionSearchOption suggestionSearchOption =
BMFSuggestionSearchOption(
keyword: text,
cityname: _locationResult.city,
location: BMFCoordinate(
_locationResult.latitude!, _locationResult.longitude!),
cityLimit: true,
);
BMFSuggestionSearch suggestionSearch = BMFSuggestionSearch();
suggestionSearch.onGetSuggestSearchResult(callback:
(BMFSuggestionSearchResult result, BMFSearchErrorCode errorCode) {
print(
"sug检索回调 result = ${result.toMap()} \n errorCode = ${errorCode}");
_list = result.suggestionList!;
if (_list.isEmpty) {
Toast.show("暂时无法搜索到该位置!");
}
isLoading = false;
setState(() {});
});
bool flag = await nearbySearch.poiNearbySearch(poiNearbySearchOption);
bool flag =
await suggestionSearch.suggestionSearch(suggestionSearchOption);
},
),
body: SafeArea(
......@@ -223,14 +234,15 @@ class AddressSelectPageState extends State<AddressSelectPage> {
onTap: () {
_index = index;
_myMapController.updateMapOptions(BMFMapOptions(
center: BMFCoordinate(_list[index].pt!.latitude,
_list[index].pt!.longitude)));
center: BMFCoordinate(
_list[index].location!.latitude,
_list[index].location!.longitude)));
/// 创建BMFMarker
BMFMarker marker = BMFMarker.icon(
position: BMFCoordinate(
_list[index].pt!.latitude,
_list[index].pt!.longitude),
_list[index].location!.latitude,
_list[index].location!.longitude),
title: 'flutterMaker',
identifier: 'flutter_marker',
icon: 'assets/images/map/icon_mark.png');
......@@ -240,8 +252,8 @@ class AddressSelectPageState extends State<AddressSelectPage> {
///设置中心点
_myMapController.setCenterCoordinate(
BMFCoordinate(_list[index].pt!.latitude,
_list[index].pt!.longitude),
BMFCoordinate(_list[index].location!.latitude,
_list[index].location!.longitude),
false);
setState(() {});
......@@ -275,7 +287,7 @@ class _AddressItem extends StatelessWidget {
this.onTap,
}) : super(key: key);
final BMFPoiInfo poi;
final BMFSuggestionInfo poi;
final bool isSelected;
final GestureTapCallback? onTap;
......@@ -291,7 +303,7 @@ class _AddressItem extends StatelessWidget {
children: <Widget>[
Expanded(
child: Text(
'${poi.province} ${poi.city} ${poi.area} ${poi.name}',
'${poi.city} ${poi.district} ${poi.address}',
),
),
Visibility(
......
......@@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+11
version: 1.0.0+12
environment:
sdk: ">=2.16.2 <3.0.0"
......