|
@@ -2,8 +2,8 @@ import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:amap_flutter_base/amap_flutter_base.dart';
|
|
import 'package:amap_flutter_base/amap_flutter_base.dart';
|
|
|
import 'package:amap_flutter_map/amap_flutter_map.dart';
|
|
import 'package:amap_flutter_map/amap_flutter_map.dart';
|
|
|
|
|
+import 'package:bbyyy/beans/address_bean_entity.dart';
|
|
|
import 'package:bbyyy/beans/poi_bean_entity.dart';
|
|
import 'package:bbyyy/beans/poi_bean_entity.dart';
|
|
|
-import 'package:bbyyy/my_tools/map_util.dart';
|
|
|
|
|
import 'package:bbyyy/my_tools/my_colors.dart';
|
|
import 'package:bbyyy/my_tools/my_colors.dart';
|
|
|
import 'package:bbyyy/my_tools/my_cookie.dart';
|
|
import 'package:bbyyy/my_tools/my_cookie.dart';
|
|
|
import 'package:bbyyy/my_tools/my_tools.dart';
|
|
import 'package:bbyyy/my_tools/my_tools.dart';
|
|
@@ -23,6 +23,10 @@ class _MapDemoPageState extends State<MapDemoPage> {
|
|
|
TextEditingController _controller = TextEditingController();
|
|
TextEditingController _controller = TextEditingController();
|
|
|
Map<String, Marker> _markers = <String, Marker>{};
|
|
Map<String, Marker> _markers = <String, Marker>{};
|
|
|
Widget _poiInfo;
|
|
Widget _poiInfo;
|
|
|
|
|
+ List<PoiBeanPois> pois;
|
|
|
|
|
+ BitmapDescriptor _markerIcon;
|
|
|
|
|
+ PoiBeanPois poi;
|
|
|
|
|
+ bool searchMode = true;
|
|
|
|
|
|
|
|
@override
|
|
@override
|
|
|
void initState() {
|
|
void initState() {
|
|
@@ -37,6 +41,9 @@ class _MapDemoPageState extends State<MapDemoPage> {
|
|
|
|
|
|
|
|
@override
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
Widget build(BuildContext context) {
|
|
|
|
|
+ if (null == _markerIcon) {
|
|
|
|
|
+ _markerIcon = BitmapDescriptor.fromIconPath('assets/地址.png');
|
|
|
|
|
+ }
|
|
|
final AMapWidget map = AMapWidget(
|
|
final AMapWidget map = AMapWidget(
|
|
|
initialCameraPosition: _kInitialPosition,
|
|
initialCameraPosition: _kInitialPosition,
|
|
|
onMapCreated: onMapCreated,
|
|
onMapCreated: onMapCreated,
|
|
@@ -48,12 +55,39 @@ class _MapDemoPageState extends State<MapDemoPage> {
|
|
|
true,
|
|
true,
|
|
|
),
|
|
),
|
|
|
markers: Set<Marker>.of(_markers.values),
|
|
markers: Set<Marker>.of(_markers.values),
|
|
|
|
|
+ onTap: (LatLng latLng){
|
|
|
|
|
+ print('================|${latLng.latitude},${latLng.longitude}|===================');
|
|
|
|
|
+ markTheClickLocation(latLng);
|
|
|
|
|
+ },
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
return Scaffold(
|
|
return Scaffold(
|
|
|
body: Column(
|
|
body: Column(
|
|
|
children: [
|
|
children: [
|
|
|
- MyViews().myAppBar('amap', context, []),
|
|
|
|
|
|
|
+ MyViews().myAppBar('选择地址', context, [
|
|
|
|
|
+ GestureDetector(
|
|
|
|
|
+ onTap: (){
|
|
|
|
|
+ setState(() {
|
|
|
|
|
+ _markers.clear();
|
|
|
|
|
+ pois?.clear();
|
|
|
|
|
+ poi = null;
|
|
|
|
|
+ searchMode = !searchMode;
|
|
|
|
|
+ _mapController.moveCamera(CameraUpdate.newCameraPosition(CameraPosition(
|
|
|
|
|
+ target: LatLng(MyCookie().location.latitude, MyCookie().location.longitude),
|
|
|
|
|
+ zoom: 15,
|
|
|
|
|
+ )));
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+ behavior: HitTestBehavior.translucent,
|
|
|
|
|
+ child: Container(
|
|
|
|
|
+ margin: EdgeInsets.symmetric(vertical: 5,horizontal: 10),
|
|
|
|
|
+ child: Text(
|
|
|
|
|
+ searchMode?'手动选择':'搜索选择',
|
|
|
|
|
+ style: TextStyle(color: MyColors.c333333, fontSize: 14),
|
|
|
|
|
+ ),
|
|
|
|
|
+ ),
|
|
|
|
|
+ )
|
|
|
|
|
+ ]),
|
|
|
Expanded(
|
|
Expanded(
|
|
|
child: Stack(
|
|
child: Stack(
|
|
|
children: [
|
|
children: [
|
|
@@ -62,6 +96,7 @@ class _MapDemoPageState extends State<MapDemoPage> {
|
|
|
width: MediaQuery.of(context).size.width,
|
|
width: MediaQuery.of(context).size.width,
|
|
|
child: map,
|
|
child: map,
|
|
|
),
|
|
),
|
|
|
|
|
+ if(searchMode)
|
|
|
Container(
|
|
Container(
|
|
|
child: Row(
|
|
child: Row(
|
|
|
children: [
|
|
children: [
|
|
@@ -83,8 +118,7 @@ class _MapDemoPageState extends State<MapDemoPage> {
|
|
|
isDense: true,
|
|
isDense: true,
|
|
|
contentPadding:
|
|
contentPadding:
|
|
|
const EdgeInsets.fromLTRB(14, 4.5, 8, 4.5)),
|
|
const EdgeInsets.fromLTRB(14, 4.5, 8, 4.5)),
|
|
|
- maxLines: 1,
|
|
|
|
|
- style: TextStyle(
|
|
|
|
|
|
|
+ maxLines: 1, style: TextStyle(
|
|
|
color: MyColors.c333333,
|
|
color: MyColors.c333333,
|
|
|
fontSize: 16,
|
|
fontSize: 16,
|
|
|
height: 1.3,
|
|
height: 1.3,
|
|
@@ -95,10 +129,11 @@ class _MapDemoPageState extends State<MapDemoPage> {
|
|
|
),
|
|
),
|
|
|
GestureDetector(
|
|
GestureDetector(
|
|
|
onTap: () {
|
|
onTap: () {
|
|
|
|
|
+ MyTools().hideKeyboard(context);
|
|
|
inquirePOI();
|
|
inquirePOI();
|
|
|
},
|
|
},
|
|
|
child: Container(
|
|
child: Container(
|
|
|
- color: Colors.blue,
|
|
|
|
|
|
|
+ color: MyColors.cFF4233,
|
|
|
child: Text(
|
|
child: Text(
|
|
|
'搜索',
|
|
'搜索',
|
|
|
style: TextStyle(color: Colors.white, fontSize: 18),
|
|
style: TextStyle(color: Colors.white, fontSize: 18),
|
|
@@ -112,7 +147,52 @@ class _MapDemoPageState extends State<MapDemoPage> {
|
|
|
),
|
|
),
|
|
|
color: Colors.white,
|
|
color: Colors.white,
|
|
|
margin: EdgeInsets.symmetric(horizontal: 15, vertical: 30),
|
|
margin: EdgeInsets.symmetric(horizontal: 15, vertical: 30),
|
|
|
- )
|
|
|
|
|
|
|
+ ),
|
|
|
|
|
+ if (poi != null)
|
|
|
|
|
+ Container(
|
|
|
|
|
+ margin: EdgeInsets.fromLTRB(
|
|
|
|
|
+ 12,
|
|
|
|
|
+ MediaQuery.of(context).size.height - 200 - 12 - 45,
|
|
|
|
|
+ 12,
|
|
|
|
|
+ 12),
|
|
|
|
|
+ width: double.infinity,
|
|
|
|
|
+ height: 150,
|
|
|
|
|
+ decoration: BoxDecoration(
|
|
|
|
|
+ color: Colors.white,
|
|
|
|
|
+ borderRadius: BorderRadius.circular(12),
|
|
|
|
|
+ boxShadow: [
|
|
|
|
|
+ BoxShadow(
|
|
|
|
|
+ color: MyColors.c7FE1E1E1,
|
|
|
|
|
+ blurRadius: 5.0,
|
|
|
|
|
+ ),
|
|
|
|
|
+ ]),
|
|
|
|
|
+ child: Column(
|
|
|
|
|
+ children: [
|
|
|
|
|
+ Text(poi == null ? '' : poi.name),
|
|
|
|
|
+ Text(poi == null ? '' : poi.address),
|
|
|
|
|
+ GestureDetector(
|
|
|
|
|
+ onTap: () {
|
|
|
|
|
+ Navigator.pop(context, poi);
|
|
|
|
|
+ },
|
|
|
|
|
+ behavior: HitTestBehavior.translucent,
|
|
|
|
|
+ child: Container(
|
|
|
|
|
+ decoration: BoxDecoration(
|
|
|
|
|
+ color: MyColors.cFF4233,
|
|
|
|
|
+ borderRadius: BorderRadius.circular(20)),
|
|
|
|
|
+ height: 40,
|
|
|
|
|
+ width: 120,
|
|
|
|
|
+ child: Text(
|
|
|
|
|
+ '就是这里',
|
|
|
|
|
+ style:
|
|
|
|
|
+ TextStyle(color: Colors.white, fontSize: 16),
|
|
|
|
|
+ ),
|
|
|
|
|
+ alignment: Alignment.center,
|
|
|
|
|
+ ),
|
|
|
|
|
+ )
|
|
|
|
|
+ ],
|
|
|
|
|
+ mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
|
|
|
+ ),
|
|
|
|
|
+ )
|
|
|
],
|
|
],
|
|
|
),
|
|
),
|
|
|
),
|
|
),
|
|
@@ -169,29 +249,34 @@ class _MapDemoPageState extends State<MapDemoPage> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void inquirePOI() {
|
|
void inquirePOI() {
|
|
|
- String v1 =
|
|
|
|
|
|
|
+ String v1 =
|
|
|
'https://restapi.amap.com/v3/place/text?keywords=${_controller.text.toString()}&city=${MyCookie().location.city}&output=json&offset=25&page=1&key=5dcd9f0ed7d51aefb5b2f73dba1069cb&extensions=all';
|
|
'https://restapi.amap.com/v3/place/text?keywords=${_controller.text.toString()}&city=${MyCookie().location.city}&output=json&offset=25&page=1&key=5dcd9f0ed7d51aefb5b2f73dba1069cb&extensions=all';
|
|
|
print(v1);
|
|
print(v1);
|
|
|
Dio().get(v1).then((value) {
|
|
Dio().get(v1).then((value) {
|
|
|
print(value);
|
|
print(value);
|
|
|
PoiBeanEntity entity =
|
|
PoiBeanEntity entity =
|
|
|
PoiBeanEntity().fromJson(json.decode(value.toString()));
|
|
PoiBeanEntity().fromJson(json.decode(value.toString()));
|
|
|
|
|
+ pois = entity.pois;
|
|
|
entity.pois.forEach((element) {
|
|
entity.pois.forEach((element) {
|
|
|
print(element.name);
|
|
print(element.name);
|
|
|
_markers[element.id] = Marker(
|
|
_markers[element.id] = Marker(
|
|
|
position: LatLng(double.parse(element.location.split(',')[1]),
|
|
position: LatLng(double.parse(element.location.split(',')[1]),
|
|
|
double.parse(element.location.split(',')[0])),
|
|
double.parse(element.location.split(',')[0])),
|
|
|
- icon: BitmapDescriptor.fromIconPath('images/地址.png'),
|
|
|
|
|
|
|
+ icon: _markerIcon,
|
|
|
infoWindow: InfoWindow(title: element.name),
|
|
infoWindow: InfoWindow(title: element.name),
|
|
|
onTap: (markerId) {
|
|
onTap: (markerId) {
|
|
|
print(markerId);
|
|
print(markerId);
|
|
|
- MapUtil.gotoAMap(double.parse(element.location.split(',')[0]),
|
|
|
|
|
- double.parse(element.location.split(',')[1]));
|
|
|
|
|
|
|
+ // MapUtil.gotoAMap(double.parse(element.location.split(',')[0]),
|
|
|
|
|
+ // double.parse(element.location.split(',')[1]));
|
|
|
|
|
+ setState(() {
|
|
|
|
|
+ poi = element;
|
|
|
|
|
+ });
|
|
|
},
|
|
},
|
|
|
);
|
|
);
|
|
|
});
|
|
});
|
|
|
setState(() {
|
|
setState(() {
|
|
|
if (entity.pois.length != 0) {
|
|
if (entity.pois.length != 0) {
|
|
|
|
|
+ showBottomSheet();
|
|
|
_mapController
|
|
_mapController
|
|
|
.moveCamera(CameraUpdate.newCameraPosition(CameraPosition(
|
|
.moveCamera(CameraUpdate.newCameraPosition(CameraPosition(
|
|
|
target: LatLng(double.parse(entity.pois[0].location.split(',')[1]),
|
|
target: LatLng(double.parse(entity.pois[0].location.split(',')[1]),
|
|
@@ -204,4 +289,89 @@ class _MapDemoPageState extends State<MapDemoPage> {
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ //显示底部弹框的功能
|
|
|
|
|
+ void showBottomSheet() {
|
|
|
|
|
+ //用于在底部打开弹框的效果
|
|
|
|
|
+ showModalBottomSheet(
|
|
|
|
|
+ builder: (BuildContext context) {
|
|
|
|
|
+ //构建弹框中的内容
|
|
|
|
|
+ return Container(
|
|
|
|
|
+ child: ListView.builder(
|
|
|
|
|
+ padding: EdgeInsets.all(8),
|
|
|
|
|
+ itemBuilder: (BuildContext context, int index) {
|
|
|
|
|
+ return GestureDetector(
|
|
|
|
|
+ onTap: () {
|
|
|
|
|
+ _mapController.moveCamera(
|
|
|
|
|
+ CameraUpdate.newCameraPosition(CameraPosition(
|
|
|
|
|
+ target: LatLng(
|
|
|
|
|
+ double.parse(pois[index].location.split(',')[1]),
|
|
|
|
|
+ double.parse(pois[index].location.split(',')[0])),
|
|
|
|
|
+ zoom: 15,
|
|
|
|
|
+ )));
|
|
|
|
|
+ Navigator.pop(context);
|
|
|
|
|
+
|
|
|
|
|
+ setState(() {
|
|
|
|
|
+ poi = pois[index];
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+ behavior: HitTestBehavior.translucent,
|
|
|
|
|
+ child: Column(
|
|
|
|
|
+ children: [
|
|
|
|
|
+ Text(
|
|
|
|
|
+ pois[index].name,
|
|
|
|
|
+ style: TextStyle(fontSize: 16),
|
|
|
|
|
+ ),
|
|
|
|
|
+ Text(
|
|
|
|
|
+ pois[index].address,
|
|
|
|
|
+ style: TextStyle(fontSize: 12),
|
|
|
|
|
+ ),
|
|
|
|
|
+ Container(
|
|
|
|
|
+ height: .5,
|
|
|
|
|
+ color: Colors.grey[200],
|
|
|
|
|
+ margin: EdgeInsets.symmetric(vertical: 10),
|
|
|
|
|
+ )
|
|
|
|
|
+ ],
|
|
|
|
|
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
+ crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
+ ),
|
|
|
|
|
+ );
|
|
|
|
|
+ },
|
|
|
|
|
+ itemCount: pois.length,
|
|
|
|
|
+ ),
|
|
|
|
|
+ );
|
|
|
|
|
+ },
|
|
|
|
|
+ context: context);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ void markTheClickLocation(LatLng latLng) {
|
|
|
|
|
+ print('https://restapi.amap.com/v3/geocode/regeo?output=json&location=${latLng.longitude},${latLng.latitude}&key=5dcd9f0ed7d51aefb5b2f73dba1069cb&radius=10&extensions=all');
|
|
|
|
|
+ Dio()
|
|
|
|
|
+ .get(
|
|
|
|
|
+ 'https://restapi.amap.com/v3/geocode/regeo?output=json&location=${latLng.longitude},${latLng.latitude}&key=5dcd9f0ed7d51aefb5b2f73dba1069cb&radius=10&extensions=all')
|
|
|
|
|
+ .then((value) {
|
|
|
|
|
+ print('value.toString()------------${value.toString()}');
|
|
|
|
|
+ AddressBeanEntity addressBeanEntity =
|
|
|
|
|
+ AddressBeanEntity().fromJson(json.decode(value.toString()));
|
|
|
|
|
+ poi = PoiBeanPois();
|
|
|
|
|
+ poi.location = '${latLng.longitude},${latLng.latitude}';
|
|
|
|
|
+ poi.pname = addressBeanEntity.regeocode.addressComponent.province;
|
|
|
|
|
+ poi.cityname = addressBeanEntity.regeocode.addressComponent.city;
|
|
|
|
|
+ poi.adname = addressBeanEntity.regeocode.addressComponent.district;
|
|
|
|
|
+ poi.address = addressBeanEntity.regeocode.pois[0].address;
|
|
|
|
|
+ poi.name = addressBeanEntity.regeocode.pois[0].name;
|
|
|
|
|
+ _markers['手动选择'] = Marker(
|
|
|
|
|
+ position: latLng,
|
|
|
|
|
+ icon: _markerIcon,
|
|
|
|
|
+ infoWindow: InfoWindow(title: poi.name),
|
|
|
|
|
+ );
|
|
|
|
|
+ _mapController.moveCamera(CameraUpdate.newCameraPosition(CameraPosition(
|
|
|
|
|
+ target: latLng,
|
|
|
|
|
+ zoom: 20,
|
|
|
|
|
+ )));
|
|
|
|
|
+ setState(() {
|
|
|
|
|
+
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|