fix MyLocationPage&LimitMapBoundsPage mis-match
This commit is contained in:
parent
61202ada16
commit
2c3e525b32
|
@ -37,7 +37,7 @@ List<Demo> mapDemos() {
|
||||||
subtitle: '定位蓝点指的是进入地图后显示当前位置点的功能',
|
subtitle: '定位蓝点指的是进入地图后显示当前位置点的功能',
|
||||||
slug: 'my-location',
|
slug: 'my-location',
|
||||||
configurations: [
|
configurations: [
|
||||||
DemoConfiguration(buildRoute: (context) => LimitMapBoundsPage())
|
DemoConfiguration(buildRoute: (context) => MyLocationPage())
|
||||||
]),
|
]),
|
||||||
Demo(
|
Demo(
|
||||||
title: '限制地图显示范围',
|
title: '限制地图显示范围',
|
||||||
|
@ -45,7 +45,7 @@ List<Demo> mapDemos() {
|
||||||
subtitle: '演示限定手机屏幕显示地图的范围',
|
subtitle: '演示限定手机屏幕显示地图的范围',
|
||||||
slug: 'limit-map-bounds',
|
slug: 'limit-map-bounds',
|
||||||
configurations: [
|
configurations: [
|
||||||
DemoConfiguration(buildRoute: (context) => MyLocationPage())
|
DemoConfiguration(buildRoute: (context) => LimitMapBoundsPage())
|
||||||
]),
|
]),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@ class MyLocationPage extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _BodyState extends State<MyLocationPage> {
|
class _BodyState extends State<MyLocationPage> {
|
||||||
|
AMapController? _mapController;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
@ -35,6 +37,15 @@ class _BodyState extends State<MyLocationPage> {
|
||||||
circleStrokeColor: Colors.blue,
|
circleStrokeColor: Colors.blue,
|
||||||
circleStrokeWidth: 1,
|
circleStrokeWidth: 1,
|
||||||
),
|
),
|
||||||
|
onLocationChanged: (loc) {
|
||||||
|
if (isLocationValid(loc)) {
|
||||||
|
print(loc);
|
||||||
|
_mapController?.moveCamera(CameraUpdate.newLatLng(loc.latLng));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onMapCreated: (controller) {
|
||||||
|
_mapController = controller;
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
|
|
|
@ -43,5 +43,6 @@ class RouteConfig {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,3 +31,4 @@ part 'src/amap_initializer.dart';
|
||||||
part 'src/amap_controller.dart';
|
part 'src/amap_controller.dart';
|
||||||
part 'src/amap_widget.dart';
|
part 'src/amap_widget.dart';
|
||||||
part 'src/amap_loader.dart';
|
part 'src/amap_loader.dart';
|
||||||
|
part 'src/utils/location_utils.dart';
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
part of amap_map;
|
||||||
|
|
||||||
|
bool isLocationValid(AMapLocation location) {
|
||||||
|
final LatLng latLng = location.latLng;
|
||||||
|
|
||||||
|
if (latLng.latitude < -90 ||
|
||||||
|
latLng.latitude > 90 ||
|
||||||
|
latLng.longitude < -180 ||
|
||||||
|
latLng.longitude > 180) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (location.accuracy < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
Loading…
Reference in New Issue