|
|
|
@ -9,7 +9,11 @@ import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter/services.dart'; |
|
|
|
|
import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; |
|
|
|
|
import 'package:flutter_baidu_mapapi_map/flutter_baidu_mapapi_map.dart'; |
|
|
|
|
import 'package:flutter_baidu_mapapi_search/flutter_baidu_mapapi_search.dart'; |
|
|
|
|
import 'package:flutter_baidu_mapapi_utils/flutter_baidu_mapapi_utils.dart'; |
|
|
|
|
import 'package:flutter_bmflocation/bdmap_location_flutter_plugin.dart'; |
|
|
|
|
import 'package:flutter_bmflocation/flutter_baidu_location_android_option.dart'; |
|
|
|
|
import 'package:flutter_bmflocation/flutter_baidu_location_ios_option.dart'; |
|
|
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; |
|
|
|
|
import 'package:huixiang/generated/l10n.dart'; |
|
|
|
|
import 'package:huixiang/retrofit/data/address.dart'; |
|
|
|
@ -27,7 +31,6 @@ class AddressMapPage extends StatefulWidget {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class _AddressMapPage extends State<AddressMapPage> { |
|
|
|
|
|
|
|
|
|
//加载自定义地图样式 |
|
|
|
|
void _loadCustomData() async { |
|
|
|
|
setState(() { |
|
|
|
@ -57,7 +60,6 @@ class _AddressMapPage extends State<AddressMapPage> {
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if (aMapFlutterLocation == null) { |
|
|
|
|
|
|
|
|
|
aMapFlutterLocation = LocationFlutterPlugin(); |
|
|
|
|
aMapFlutterLocation.onResultCallback().listen((event) { |
|
|
|
|
print("event: ${jsonEncode(event)}"); |
|
|
|
@ -72,72 +74,113 @@ class _AddressMapPage extends State<AddressMapPage> {
|
|
|
|
|
} else { |
|
|
|
|
latLng = BMFCoordinate(event["latitude"], event["longitude"]); |
|
|
|
|
} |
|
|
|
|
saveLatLng(latLng); |
|
|
|
|
if (_mapController != null) |
|
|
|
|
_mapController.updateMapOptions( |
|
|
|
|
BMFMapOptions( |
|
|
|
|
center: latLng, |
|
|
|
|
zoomLevel: 15, |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
searchPoi(latLng); |
|
|
|
|
BMFCalculateUtils.coordConvert( |
|
|
|
|
coordinate: latLng, |
|
|
|
|
fromType: BMF_COORD_TYPE.COMMON, |
|
|
|
|
toType: BMF_COORD_TYPE.BD09LL) |
|
|
|
|
.then((value) { |
|
|
|
|
saveLatLng(value); |
|
|
|
|
if (_mapController != null) { |
|
|
|
|
this.latLng = value; |
|
|
|
|
addMarker(); |
|
|
|
|
_mapController.updateMapOptions( |
|
|
|
|
BMFMapOptions( |
|
|
|
|
center: latLng, |
|
|
|
|
zoomLevel: 15, |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
searchPoi(latLng); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
aMapFlutterLocation.prepareLoc({ |
|
|
|
|
"coorType": "bd09ll", |
|
|
|
|
"isNeedAddres": false, |
|
|
|
|
"isNeedAltitude": false, |
|
|
|
|
"isNeedLocationPoiList": false, |
|
|
|
|
"isNeedLocationDescribe": false, |
|
|
|
|
"isNeedNewVersionRgc": false, |
|
|
|
|
"scanspan": 0, |
|
|
|
|
"openGps": true, |
|
|
|
|
"locationMode": 2, |
|
|
|
|
}, { |
|
|
|
|
"locationMode": "kCLLocationAccuracyBest", |
|
|
|
|
"locationTimeout": 10, |
|
|
|
|
"reGeocodeTimeout": 10, |
|
|
|
|
"activityType": "CLActivityTypeAutomotiveNavigation", |
|
|
|
|
"BMKLocationCoordinateType": "BMKLocationCoordinateTypeBMK09LL", |
|
|
|
|
"BMKLocationCoordinateType": "BMKLocationCoordinateTypeBMK09LL", |
|
|
|
|
"isNeedNewVersionRgc": false, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
_loadCustomData(); |
|
|
|
|
_setLocOption(); |
|
|
|
|
|
|
|
|
|
getLatLng(); |
|
|
|
|
startLocation(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// 设置android端和ios端定位参数 |
|
|
|
|
void _setLocOption() { |
|
|
|
|
/// android 端设置定位参数 |
|
|
|
|
BaiduLocationAndroidOption androidOption = new BaiduLocationAndroidOption(); |
|
|
|
|
androidOption.setCoorType("GCJ02"); // 设置返回的位置坐标系类型 |
|
|
|
|
androidOption.setIsNeedAltitude(true); // 设置是否需要返回海拔高度信息 |
|
|
|
|
androidOption.setIsNeedAddres(true); // 设置是否需要返回地址信息 |
|
|
|
|
androidOption.setIsNeedLocationPoiList(true); // 设置是否需要返回周边poi信息 |
|
|
|
|
androidOption.setIsNeedNewVersionRgc(true); // 设置是否需要返回最新版本rgc信息 |
|
|
|
|
androidOption.setIsNeedLocationDescribe(true); // 设置是否需要返回位置描述 |
|
|
|
|
androidOption.setOpenGps(true); // 设置是否需要使用gps |
|
|
|
|
androidOption.setLocationMode(LocationMode.Hight_Accuracy); // 设置定位模式 |
|
|
|
|
androidOption.setScanspan(0); // 设置发起定位请求时间间隔 |
|
|
|
|
|
|
|
|
|
Map androidMap = androidOption.getMap(); |
|
|
|
|
|
|
|
|
|
/// ios 端设置定位参数 |
|
|
|
|
BaiduLocationIOSOption iosOption = new BaiduLocationIOSOption(); |
|
|
|
|
iosOption.setIsNeedNewVersionRgc(true); // 设置是否需要返回最新版本rgc信息 |
|
|
|
|
iosOption.setBMKLocationCoordinateType( |
|
|
|
|
"BMKLocationCoordinateTypeGCJ02"); // 设置返回的位置坐标系类型 |
|
|
|
|
iosOption.setActivityType("CLActivityTypeAutomotiveNavigation"); // 设置应用位置类型 |
|
|
|
|
iosOption.setLocationTimeout(10); // 设置位置获取超时时间 |
|
|
|
|
iosOption.setDesiredAccuracy("kCLLocationAccuracyBest"); // 设置预期精度参数 |
|
|
|
|
iosOption.setReGeocodeTimeout(10); // 设置获取地址信息超时时间 |
|
|
|
|
iosOption.setDistanceFilter(1000); // 设置定位最小更新距离 |
|
|
|
|
iosOption.setAllowsBackgroundLocationUpdates(true); // 是否允许后台定位 |
|
|
|
|
iosOption.setPauseLocUpdateAutomatically(true); // 定位是否会被系统自动暂停 |
|
|
|
|
|
|
|
|
|
Map iosMap = iosOption.getMap(); |
|
|
|
|
|
|
|
|
|
aMapFlutterLocation.prepareLoc(androidMap, iosMap); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
List<Address> poiList; |
|
|
|
|
|
|
|
|
|
searchPoi(BMFCoordinate latLng) async { |
|
|
|
|
keyWord = textEditingController.text; |
|
|
|
|
var addressPoi = await apiService.searchPoi( |
|
|
|
|
"${latLng.latitude}", "${latLng.longitude}", keyWord, 20, 1); |
|
|
|
|
List<dynamic> poi = addressPoi['pois']; |
|
|
|
|
poiList = poi |
|
|
|
|
.map((e) => Address.fromJson({ |
|
|
|
|
"address": e["address"] is List ? "" : e["address"], |
|
|
|
|
"area": e["adname"], |
|
|
|
|
"city": e["cityname"], |
|
|
|
|
"province": e["pname"], |
|
|
|
|
"latitude": e["location"].toString().split(",")[0], |
|
|
|
|
"longitude": e["location"].toString().split(",")[1], |
|
|
|
|
"cityInfo": e["name"], |
|
|
|
|
"id": "", |
|
|
|
|
"mid": "", |
|
|
|
|
"phone": "", |
|
|
|
|
"tag": "", |
|
|
|
|
"username": "", |
|
|
|
|
"isDefault": 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 |
|
|
|
|
.map((e) => Address.fromJson({ |
|
|
|
|
"address": e.address, |
|
|
|
|
"area": e.name, |
|
|
|
|
"city": e.city, |
|
|
|
|
"province": e.province, |
|
|
|
|
"latitude": e.pt.latitude, |
|
|
|
|
"longitude": e.pt.longitude, |
|
|
|
|
"cityInfo": e.name, |
|
|
|
|
"id": "", |
|
|
|
|
"mid": "", |
|
|
|
|
"phone": "", |
|
|
|
|
"tag": "", |
|
|
|
|
"username": "", |
|
|
|
|
"isDefault": true, |
|
|
|
|
})) |
|
|
|
|
.toList(); |
|
|
|
|
print("object112221: ${poiList.length}"); |
|
|
|
|
setState(() { |
|
|
|
|
time = DateTime.now().millisecondsSinceEpoch; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
bmfPoiNearbySearch.poiNearbySearch(BMFPoiNearbySearchOption( |
|
|
|
|
keywords: ["all"], |
|
|
|
|
radius: 100000, |
|
|
|
|
location: latLng, |
|
|
|
|
pageSize: 20, |
|
|
|
|
pageIndex: 0, |
|
|
|
|
isRadiusLimit: true, |
|
|
|
|
)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int time = 0; |
|
|
|
|
|
|
|
|
|
startLocation() async { |
|
|
|
|
if (!(await Permission.locationWhenInUse.serviceStatus.isEnabled)) { |
|
|
|
|
enableLocation(); |
|
|
|
@ -173,7 +216,7 @@ class _AddressMapPage extends State<AddressMapPage> {
|
|
|
|
|
S.of(context).nindingweigongnengweikaiqi, |
|
|
|
|
S.of(context).weilexiangnintuijianfujindemendianxinxi, |
|
|
|
|
S.of(context).dakaidingwei, |
|
|
|
|
(result) async { |
|
|
|
|
(result) async { |
|
|
|
|
if (result) { |
|
|
|
|
final AndroidIntent intent = AndroidIntent( |
|
|
|
|
action: 'action_location_source_settings', |
|
|
|
@ -197,7 +240,7 @@ class _AddressMapPage extends State<AddressMapPage> {
|
|
|
|
|
S.of(context).nindingweiquanxianweiyunxu, |
|
|
|
|
S.of(context).weilexiangnintuijianfujindemendianxinxi, |
|
|
|
|
S.of(context).kaiqiquanxian, |
|
|
|
|
(result) async { |
|
|
|
|
(result) async { |
|
|
|
|
if (result) { |
|
|
|
|
await openAppSettings(); |
|
|
|
|
if (await Permission.location.isGranted) { |
|
|
|
@ -213,11 +256,47 @@ class _AddressMapPage extends State<AddressMapPage> {
|
|
|
|
|
BMFMapController _mapController; |
|
|
|
|
|
|
|
|
|
void onMapCreated(BMFMapController controller) { |
|
|
|
|
controller.setMapRegionDidChangeCallback(callback: (status) { |
|
|
|
|
center = status.targetGeoPt; |
|
|
|
|
searchPoi(center); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
setState(() { |
|
|
|
|
_mapController = controller; |
|
|
|
|
_mapController.showUserLocation(true); |
|
|
|
|
|
|
|
|
|
_loadCustomData(); |
|
|
|
|
addMarker(); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BMFCoordinate latLng; |
|
|
|
|
BMFMarker bmfMarker; |
|
|
|
|
|
|
|
|
|
addMarker() { |
|
|
|
|
if (latLng == null) return; |
|
|
|
|
if (bmfMarker == null && _mapController != null) { |
|
|
|
|
print("map_wid: ${MediaQuery.of(context).size.width}"); |
|
|
|
|
print("map_hei: ${MediaQuery.of(context).size.height}"); |
|
|
|
|
|
|
|
|
|
bmfMarker = BMFMarker( |
|
|
|
|
position: latLng, |
|
|
|
|
screenPointToLock: BMFPoint(MediaQuery.of(context).size.width / 2, |
|
|
|
|
MediaQuery.of(context).size.height / 4), |
|
|
|
|
isLockedToScreen: true, |
|
|
|
|
centerOffset: BMFPoint(0.5, 0.9), |
|
|
|
|
enabled: false, |
|
|
|
|
icon: "assets/image/icon_map_marker.png", |
|
|
|
|
draggable: false, |
|
|
|
|
); |
|
|
|
|
_mapController.addMarker(bmfMarker); |
|
|
|
|
} |
|
|
|
|
bmfMarker.updateIsLockedToScreen( |
|
|
|
|
true, |
|
|
|
|
BMFPoint(MediaQuery.of(context).size.width / 2, |
|
|
|
|
MediaQuery.of(context).size.height / 4)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
saveLatLng(BMFCoordinate latLng) async { |
|
|
|
|
SharedPreferences prefs = await SharedPreferences.getInstance(); |
|
|
|
|
await prefs.setString("latitude", "${latLng.latitude}"); |
|
|
|
@ -231,8 +310,9 @@ class _AddressMapPage extends State<AddressMapPage> {
|
|
|
|
|
_mapController.updateMapOptions( |
|
|
|
|
BMFMapOptions( |
|
|
|
|
center: BMFCoordinate( |
|
|
|
|
double.tryParse(value.getString("latitude")), |
|
|
|
|
double.tryParse(value.getString("longitude"))), |
|
|
|
|
double.tryParse(value.getString("latitude")), |
|
|
|
|
double.tryParse(value.getString("longitude")), |
|
|
|
|
), |
|
|
|
|
zoomLevel: 15, |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
@ -277,18 +357,18 @@ class _AddressMapPage extends State<AddressMapPage> {
|
|
|
|
|
// ].toSet(), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Center( |
|
|
|
|
child: IgnorePointer( |
|
|
|
|
child: Container( |
|
|
|
|
margin: EdgeInsets.only(bottom: 44.h), |
|
|
|
|
child: Image.asset( |
|
|
|
|
"assets/image/icon_address_location.png", |
|
|
|
|
width: 66.w, |
|
|
|
|
height: 75.h, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
// Center( |
|
|
|
|
// child: IgnorePointer( |
|
|
|
|
// child: Container( |
|
|
|
|
// margin: EdgeInsets.only(bottom: 44.h), |
|
|
|
|
// child: Image.asset( |
|
|
|
|
// "assets/image/icon_address_location.png", |
|
|
|
|
// width: 66.w, |
|
|
|
|
// height: 75.h, |
|
|
|
|
// ), |
|
|
|
|
// ), |
|
|
|
|
// ), |
|
|
|
|
// ), |
|
|
|
|
searchWidget(), |
|
|
|
|
Positioned( |
|
|
|
|
right: 17, |
|
|
|
@ -372,7 +452,7 @@ class _AddressMapPage extends State<AddressMapPage> {
|
|
|
|
|
color: Color(0xFF4C4C4C), |
|
|
|
|
fontSize: 14.sp, |
|
|
|
|
), |
|
|
|
|
) |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
@ -386,16 +466,17 @@ class _AddressMapPage extends State<AddressMapPage> {
|
|
|
|
|
margin: EdgeInsets.fromLTRB(16, 48, 16, 8), |
|
|
|
|
padding: EdgeInsets.fromLTRB(10, 6, 16, 6), |
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
color: Colors.white, |
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(4)), |
|
|
|
|
boxShadow: [ |
|
|
|
|
BoxShadow( |
|
|
|
|
color: Colors.black.withAlpha(12), |
|
|
|
|
offset: Offset(0, 3), |
|
|
|
|
blurRadius: 14, |
|
|
|
|
spreadRadius: 0, |
|
|
|
|
) |
|
|
|
|
]), |
|
|
|
|
color: Colors.white, |
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(4)), |
|
|
|
|
boxShadow: [ |
|
|
|
|
BoxShadow( |
|
|
|
|
color: Colors.black.withAlpha(12), |
|
|
|
|
offset: Offset(0, 3), |
|
|
|
|
blurRadius: 14, |
|
|
|
|
spreadRadius: 0, |
|
|
|
|
) |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
child: Row( |
|
|
|
|
mainAxisSize: MainAxisSize.max, |
|
|
|
|
children: [ |
|
|
|
|