Browse Source

image

null_safety
fmk 3 years ago
parent
commit
fb612aadb7
  1. 89
      lib/address/address_map_page.dart

89
lib/address/address_map_page.dart

@ -138,31 +138,54 @@ class _AddressMapPage extends State<AddressMapPage> {
aMapFlutterLocation.prepareLoc(androidMap, iosMap); aMapFlutterLocation.prepareLoc(androidMap, iosMap);
} }
List<BMFPoiInfo> poiList; List<Address> poiList;
searchPoi(BMFCoordinate latLng) async { searchPoi(BMFCoordinate latLng) async {
keyWord = textEditingController.text; keyWord = textEditingController.text;
print("keyWord: ${keyWord}");
BMFPoiNearbySearch bmfPoiNearbySearch = BMFPoiNearbySearch(); var addressPoi = await apiService.searchPoi(
bmfPoiNearbySearch.onGetPoiNearbySearchResult( "${latLng.latitude}", "${latLng.longitude}", keyWord, 20, 1);
callback: (BMFPoiSearchResult result, BMFSearchErrorCode errorCode) { List<dynamic> poi = addressPoi['pois'];
// if ((DateTime.now().millisecondsSinceEpoch - time) > 2000) { poiList = poi
result.poiInfoList.map((e) => print("sssssssssss:${e.toMap()}")); .map((e) => Address.fromJson({
poiList = result.poiInfoList; "address": e["address"] is List ? "" : e["address"],
print("object112221: ${poiList.length}"); "area": e["adname"],
setState(() { "city": e["cityname"],
time = DateTime.now().millisecondsSinceEpoch; "province": e["pname"],
}); "latitude": e["location"].toString().split(",")[0],
// } "longitude": e["location"].toString().split(",")[1],
}); "cityInfo": e["name"],
bmfPoiNearbySearch.poiNearbySearch(BMFPoiNearbySearchOption( "id": "",
keywords: ["附近"], "mid": "",
radius: 100000, "phone": "",
location: latLng, "tag": "",
pageSize: 20, "username": "",
pageIndex: 0, "isDefault": true,
isRadiusLimit: true, }))
)); .toList();
setState(() {});
// BMFPoiNearbySearch bmfPoiNearbySearch = BMFPoiNearbySearch();
// bmfPoiNearbySearch.onGetPoiNearbySearchResult(
// callback: (BMFPoiSearchResult result, BMFSearchErrorCode errorCode) {
// // if ((DateTime.now().millisecondsSinceEpoch - time) > 2000) {
// result.poiInfoList.map((e) => print("sssssssssss:${e.toMap()}"));
// poiList = result.poiInfoList;
// print("object112221: ${poiList.length}");
// setState(() {
// time = DateTime.now().millisecondsSinceEpoch;
// });
// // }
// });
// bmfPoiNearbySearch.poiNearbySearch(BMFPoiNearbySearchOption(
// keywords: [" "],
// tags: ["小区","住宅","地标","建筑"],
// radius: 100000,
// location: latLng,
// pageSize: 20,
// pageIndex: 0,
// isRadiusLimit: true,
// ));
} }
int time = 0; int time = 0;
@ -240,11 +263,21 @@ class _AddressMapPage extends State<AddressMapPage> {
} }
BMFMapController _mapController; BMFMapController _mapController;
BMFCoordinate bmfCoordinate;
void onMapCreated(BMFMapController controller) { void onMapCreated(BMFMapController controller) {
controller.setMapRegionDidChangeCallback(callback: (status) { controller.setMapRegionDidChangeCallback(callback: (status) {
center = status.targetGeoPt; BMFMapStatus bmfMapStatus = status;
searchPoi(center); print("status: ${bmfMapStatus.toMap()}");
if(bmfCoordinate != null && bmfCoordinate.longitude == status.targetGeoPt.longitude && bmfCoordinate.latitude == status.targetGeoPt.latitude) {
if ((DateTime.now().millisecondsSinceEpoch - time) > 1000) {
center = status.targetGeoPt;
searchPoi(center);
time = DateTime.now().millisecondsSinceEpoch;
}
} else {
bmfCoordinate = status.targetGeoPt;
}
}); });
setState(() { setState(() {
@ -265,7 +298,6 @@ class _AddressMapPage extends State<AddressMapPage> {
print("map_wid: ${MediaQuery.of(context).size.width}"); print("map_wid: ${MediaQuery.of(context).size.width}");
print("map_hei: ${MediaQuery.of(context).size.height}"); print("map_hei: ${MediaQuery.of(context).size.height}");
bmfMarker = BMFMarker( bmfMarker = BMFMarker(
position: latLng, position: latLng,
screenPointToLock: BMFPoint((Platform.isIOS ? MediaQuery.of(context).size.width : window.physicalSize.width) / 2, screenPointToLock: BMFPoint((Platform.isIOS ? MediaQuery.of(context).size.width : window.physicalSize.width) / 2,
@ -392,7 +424,7 @@ class _AddressMapPage extends State<AddressMapPage> {
itemBuilder: (context, position) { itemBuilder: (context, position) {
return InkWell( return InkWell(
onTap: () { onTap: () {
Navigator.of(context).pop(poiList[position].toMap()); Navigator.of(context).pop(poiList[position].toJson());
}, },
child: addressItem(poiList[position]), child: addressItem(poiList[position]),
); );
@ -413,8 +445,7 @@ class _AddressMapPage extends State<AddressMapPage> {
); );
} }
Widget addressItem(BMFPoiInfo address) { Widget addressItem(Address address) {
print("addresss:${address.toMap()}");
return Container( return Container(
margin: EdgeInsets.symmetric(vertical: 16.h, horizontal: 16.w), margin: EdgeInsets.symmetric(vertical: 16.h, horizontal: 16.w),
child: Column( child: Column(
@ -422,7 +453,7 @@ class _AddressMapPage extends State<AddressMapPage> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text( Text(
address.name ?? "", address.cityInfo ?? "",
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
style: TextStyle( style: TextStyle(
fontSize: 16.sp, fontSize: 16.sp,

Loading…
Cancel
Save