|
|
@ -34,21 +34,21 @@ class _AddressMapPage extends State<AddressMapPage> { |
|
|
|
//加载自定义地图样式 |
|
|
|
//加载自定义地图样式 |
|
|
|
void _loadCustomData() async { |
|
|
|
void _loadCustomData() async { |
|
|
|
setState(() { |
|
|
|
setState(() { |
|
|
|
_mapController.setCustomMapStyle('assets/map_style/chatian.sty', 0); |
|
|
|
_mapController?.setCustomMapStyle('assets/map_style/chatian.sty', 0); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
LocationFlutterPlugin aMapFlutterLocation; |
|
|
|
LocationFlutterPlugin? aMapFlutterLocation; |
|
|
|
String city = "武汉市"; |
|
|
|
String? city = "武汉市"; |
|
|
|
String keyWord = ""; |
|
|
|
String? keyWord = ""; |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
void dispose() { |
|
|
|
void dispose() { |
|
|
|
super.dispose(); |
|
|
|
super.dispose(); |
|
|
|
aMapFlutterLocation.stopLocation(); |
|
|
|
aMapFlutterLocation?.stopLocation(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ApiService apiService; |
|
|
|
ApiService? apiService; |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
void initState() { |
|
|
|
void initState() { |
|
|
@ -56,35 +56,38 @@ class _AddressMapPage extends State<AddressMapPage> { |
|
|
|
|
|
|
|
|
|
|
|
SharedPreferences.getInstance().then((value) => { |
|
|
|
SharedPreferences.getInstance().then((value) => { |
|
|
|
apiService = ApiService(Dio(), |
|
|
|
apiService = ApiService(Dio(), |
|
|
|
context: context, token: value.getString('token')), |
|
|
|
context: context, token: value.getString('token')!), |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (aMapFlutterLocation == null) { |
|
|
|
if (aMapFlutterLocation == null) { |
|
|
|
aMapFlutterLocation = LocationFlutterPlugin(); |
|
|
|
aMapFlutterLocation = LocationFlutterPlugin(); |
|
|
|
aMapFlutterLocation.requestPermission(); |
|
|
|
aMapFlutterLocation!.requestPermission(); |
|
|
|
aMapFlutterLocation.onResultCallback().listen((event) { |
|
|
|
aMapFlutterLocation!.onResultCallback().listen((event) { |
|
|
|
print("event: ${jsonEncode(event)}"); |
|
|
|
print("event: ${jsonEncode(event)}"); |
|
|
|
|
|
|
|
event = event as Map<String, Object>; |
|
|
|
if (event != null && |
|
|
|
if (event != null && |
|
|
|
event["latitude"] != null && |
|
|
|
event["latitude"] != null && |
|
|
|
event["longitude"] != null) { |
|
|
|
event["longitude"] != null) { |
|
|
|
city = event["city"]; |
|
|
|
city = event["city"] as String; |
|
|
|
BMFCoordinate latLng; |
|
|
|
BMFCoordinate latLng; |
|
|
|
if (event["latitude"] is String && event["longitude"] is String) { |
|
|
|
if (event["latitude"] is String && event["longitude"] is String) { |
|
|
|
latLng = BMFCoordinate(double.tryParse(event["latitude"]), |
|
|
|
latLng = BMFCoordinate( |
|
|
|
double.tryParse(event["longitude"])); |
|
|
|
double.tryParse(event["latitude"] as String)!, |
|
|
|
|
|
|
|
double.tryParse(event["longitude"] as String)! |
|
|
|
|
|
|
|
); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
latLng = BMFCoordinate(event["latitude"], event["longitude"]); |
|
|
|
latLng = BMFCoordinate(event["latitude"] as double, event["longitude"] as double); |
|
|
|
} |
|
|
|
} |
|
|
|
BMFCalculateUtils.coordConvert( |
|
|
|
BMFCalculateUtils.coordConvert( |
|
|
|
coordinate: latLng, |
|
|
|
coordinate: latLng, |
|
|
|
fromType: BMF_COORD_TYPE.COMMON, |
|
|
|
fromType: BMF_COORD_TYPE.COMMON, |
|
|
|
toType: BMF_COORD_TYPE.BD09LL) |
|
|
|
toType: BMF_COORD_TYPE.BD09LL) |
|
|
|
.then((value) { |
|
|
|
.then((value) { |
|
|
|
saveLatLng(value); |
|
|
|
saveLatLng(value); |
|
|
|
if (_mapController != null) { |
|
|
|
if (_mapController != null) { |
|
|
|
this.latLng = Platform.isIOS ? value : latLng; |
|
|
|
this.latLng = Platform.isIOS ? value! : latLng; |
|
|
|
addMarker(); |
|
|
|
addMarker(); |
|
|
|
_mapController.updateMapOptions( |
|
|
|
_mapController?.updateMapOptions( |
|
|
|
BMFMapOptions( |
|
|
|
BMFMapOptions( |
|
|
|
center: latLng, |
|
|
|
center: latLng, |
|
|
|
zoomLevel: 15, |
|
|
|
zoomLevel: 15, |
|
|
@ -134,15 +137,15 @@ class _AddressMapPage extends State<AddressMapPage> { |
|
|
|
|
|
|
|
|
|
|
|
Map iosMap = iosOption.getMap(); |
|
|
|
Map iosMap = iosOption.getMap(); |
|
|
|
|
|
|
|
|
|
|
|
aMapFlutterLocation.prepareLoc(androidMap, iosMap); |
|
|
|
aMapFlutterLocation?.prepareLoc(androidMap, iosMap); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<Address> poiList; |
|
|
|
List<Address>? poiList; |
|
|
|
|
|
|
|
|
|
|
|
searchPoi(BMFCoordinate latLng) async { |
|
|
|
searchPoi(BMFCoordinate latLng) async { |
|
|
|
keyWord = textEditingController.text; |
|
|
|
keyWord = textEditingController.text; |
|
|
|
print("keyWord: ${keyWord}"); |
|
|
|
print("keyWord: ${keyWord}"); |
|
|
|
var addressPoi = await apiService.searchPoi( |
|
|
|
var addressPoi = await apiService!.searchPoi( |
|
|
|
"${latLng.latitude}", "${latLng.longitude}", keyWord, 20, 1); |
|
|
|
"${latLng.latitude}", "${latLng.longitude}", keyWord, 20, 1); |
|
|
|
List<dynamic> poi = addressPoi['pois']; |
|
|
|
List<dynamic> poi = addressPoi['pois']; |
|
|
|
poiList = poi |
|
|
|
poiList = poi |
|
|
@ -199,11 +202,11 @@ class _AddressMapPage extends State<AddressMapPage> { |
|
|
|
requestDialog(); |
|
|
|
requestDialog(); |
|
|
|
} else if (await Permission.location.isGranted) { |
|
|
|
} else if (await Permission.location.isGranted) { |
|
|
|
// EasyLoading.show(status: S.of(context).zhengzaijiazai); |
|
|
|
// EasyLoading.show(status: S.of(context).zhengzaijiazai); |
|
|
|
aMapFlutterLocation.startLocation(); |
|
|
|
aMapFlutterLocation?.startLocation(); |
|
|
|
Future.delayed(Duration(seconds: 6), () { |
|
|
|
Future.delayed(Duration(seconds: 6), () { |
|
|
|
EasyLoading.dismiss(); |
|
|
|
EasyLoading.dismiss(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} else if (await Permission.location.isUndetermined) { |
|
|
|
} else if (await Permission.location.isLimited) { |
|
|
|
await Permission.location.request(); |
|
|
|
await Permission.location.request(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (Platform.isIOS) { |
|
|
|
if (Platform.isIOS) { |
|
|
@ -261,18 +264,18 @@ class _AddressMapPage extends State<AddressMapPage> { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
BMFMapController _mapController; |
|
|
|
BMFMapController? _mapController; |
|
|
|
BMFCoordinate bmfCoordinate; |
|
|
|
BMFCoordinate? bmfCoordinate; |
|
|
|
|
|
|
|
|
|
|
|
void onMapCreated(BMFMapController controller) { |
|
|
|
void onMapCreated(BMFMapController controller) { |
|
|
|
controller.setMapRegionDidChangeCallback(callback: (status) { |
|
|
|
controller.setMapRegionDidChangeCallback(callback: (status) { |
|
|
|
BMFMapStatus bmfMapStatus = status; |
|
|
|
BMFMapStatus bmfMapStatus = status; |
|
|
|
print("status: ${bmfMapStatus.toMap()}"); |
|
|
|
print("status: ${bmfMapStatus.toMap()}"); |
|
|
|
if (bmfCoordinate != null && |
|
|
|
if (bmfCoordinate != null && |
|
|
|
bmfCoordinate.longitude == status.targetGeoPt.longitude && |
|
|
|
bmfCoordinate!.longitude == status.targetGeoPt?.longitude && |
|
|
|
bmfCoordinate.latitude == status.targetGeoPt.latitude) { |
|
|
|
bmfCoordinate!.latitude == status.targetGeoPt?.latitude) { |
|
|
|
if ((DateTime.now().millisecondsSinceEpoch - time) > 1000) { |
|
|
|
if ((DateTime.now().millisecondsSinceEpoch - time) > 1000) { |
|
|
|
center = status.targetGeoPt; |
|
|
|
center = status.targetGeoPt!; |
|
|
|
searchPoi(center); |
|
|
|
searchPoi(center); |
|
|
|
time = DateTime.now().millisecondsSinceEpoch; |
|
|
|
time = DateTime.now().millisecondsSinceEpoch; |
|
|
|
} |
|
|
|
} |
|
|
@ -283,14 +286,14 @@ class _AddressMapPage extends State<AddressMapPage> { |
|
|
|
|
|
|
|
|
|
|
|
setState(() { |
|
|
|
setState(() { |
|
|
|
_mapController = controller; |
|
|
|
_mapController = controller; |
|
|
|
_mapController.showUserLocation(true); |
|
|
|
_mapController?.showUserLocation(true); |
|
|
|
_loadCustomData(); |
|
|
|
_loadCustomData(); |
|
|
|
addMarker(); |
|
|
|
addMarker(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
BMFCoordinate latLng; |
|
|
|
BMFCoordinate? latLng; |
|
|
|
BMFMarker bmfMarker; |
|
|
|
BMFMarker? bmfMarker; |
|
|
|
|
|
|
|
|
|
|
|
addMarker() { |
|
|
|
addMarker() { |
|
|
|
if (latLng == null) return; |
|
|
|
if (latLng == null) return; |
|
|
@ -299,7 +302,7 @@ class _AddressMapPage extends State<AddressMapPage> { |
|
|
|
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( |
|
|
|
screenPointToLock: BMFPoint( |
|
|
|
(Platform.isIOS |
|
|
|
(Platform.isIOS |
|
|
|
? MediaQuery.of(context).size.width |
|
|
|
? MediaQuery.of(context).size.width |
|
|
@ -314,9 +317,9 @@ class _AddressMapPage extends State<AddressMapPage> { |
|
|
|
icon: "assets/image/icon_address_location.png", |
|
|
|
icon: "assets/image/icon_address_location.png", |
|
|
|
draggable: false, |
|
|
|
draggable: false, |
|
|
|
); |
|
|
|
); |
|
|
|
_mapController.addMarker(bmfMarker); |
|
|
|
_mapController!.addMarker(bmfMarker!); |
|
|
|
} |
|
|
|
} |
|
|
|
bmfMarker.updateIsLockedToScreen( |
|
|
|
bmfMarker?.updateIsLockedToScreen( |
|
|
|
true, |
|
|
|
true, |
|
|
|
BMFPoint( |
|
|
|
BMFPoint( |
|
|
|
(Platform.isIOS |
|
|
|
(Platform.isIOS |
|
|
@ -329,7 +332,8 @@ class _AddressMapPage extends State<AddressMapPage> { |
|
|
|
4)); |
|
|
|
4)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
saveLatLng(BMFCoordinate latLng) async { |
|
|
|
saveLatLng(BMFCoordinate? latLng) async { |
|
|
|
|
|
|
|
if(latLng == null) return; |
|
|
|
SharedPreferences prefs = await SharedPreferences.getInstance(); |
|
|
|
SharedPreferences prefs = await SharedPreferences.getInstance(); |
|
|
|
await prefs.setString("latitude", "${latLng.latitude}"); |
|
|
|
await prefs.setString("latitude", "${latLng.latitude}"); |
|
|
|
await prefs.setString("longitude", "${latLng.longitude}"); |
|
|
|
await prefs.setString("longitude", "${latLng.longitude}"); |
|
|
@ -339,11 +343,11 @@ class _AddressMapPage extends State<AddressMapPage> { |
|
|
|
SharedPreferences.getInstance().then((value) => { |
|
|
|
SharedPreferences.getInstance().then((value) => { |
|
|
|
setState(() { |
|
|
|
setState(() { |
|
|
|
if (_mapController != null) { |
|
|
|
if (_mapController != null) { |
|
|
|
_mapController.updateMapOptions( |
|
|
|
_mapController!.updateMapOptions( |
|
|
|
BMFMapOptions( |
|
|
|
BMFMapOptions( |
|
|
|
center: BMFCoordinate( |
|
|
|
center: BMFCoordinate( |
|
|
|
double.tryParse(value.getString("latitude")), |
|
|
|
double.tryParse(value.getString("latitude")!)!, |
|
|
|
double.tryParse(value.getString("longitude")), |
|
|
|
double.tryParse(value.getString("longitude")!)!, |
|
|
|
), |
|
|
|
), |
|
|
|
zoomLevel: 15, |
|
|
|
zoomLevel: 15, |
|
|
|
), |
|
|
|
), |
|
|
@ -353,7 +357,7 @@ class _AddressMapPage extends State<AddressMapPage> { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
BMFMapWidget map; |
|
|
|
BMFMapWidget? map; |
|
|
|
BMFCoordinate center = BMFCoordinate(30.553111, 114.342366); |
|
|
|
BMFCoordinate center = BMFCoordinate(30.553111, 114.342366); |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
@ -433,16 +437,16 @@ class _AddressMapPage extends State<AddressMapPage> { |
|
|
|
child: Container( |
|
|
|
child: Container( |
|
|
|
child: ListView.separated( |
|
|
|
child: ListView.separated( |
|
|
|
padding: EdgeInsets.symmetric(vertical: 0), |
|
|
|
padding: EdgeInsets.symmetric(vertical: 0), |
|
|
|
itemCount: poiList != null ? poiList.length : 0, |
|
|
|
itemCount: poiList != null ? poiList!.length : 0, |
|
|
|
itemBuilder: (context, position) { |
|
|
|
itemBuilder: (context, position) { |
|
|
|
return InkWell( |
|
|
|
return InkWell( |
|
|
|
onTap: () { |
|
|
|
onTap: () { |
|
|
|
Navigator.of(context).pop(poiList[position].toJson()); |
|
|
|
Navigator.of(context).pop(poiList![position].toJson()); |
|
|
|
}, |
|
|
|
}, |
|
|
|
child: addressItem(poiList[position]), |
|
|
|
child: addressItem(poiList![position]), |
|
|
|
); |
|
|
|
); |
|
|
|
}, |
|
|
|
}, |
|
|
|
separatorBuilder: (contetx, position) { |
|
|
|
separatorBuilder: (context, position) { |
|
|
|
return Container( |
|
|
|
return Container( |
|
|
|
height: 1, |
|
|
|
height: 1, |
|
|
|
margin: EdgeInsets.symmetric(horizontal: 16.w), |
|
|
|
margin: EdgeInsets.symmetric(horizontal: 16.w), |
|
|
|