Skip to content

Commit

Permalink
fix MyLocationPage&LimitMapBoundsPage mis-match
Browse files Browse the repository at this point in the history
  • Loading branch information
kuloud committed Jun 27, 2024
1 parent 61202ad commit 2c3e525
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions example/lib/data/demos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ List<Demo> mapDemos() {
subtitle: '定位蓝点指的是进入地图后显示当前位置点的功能',
slug: 'my-location',
configurations: [
DemoConfiguration(buildRoute: (context) => LimitMapBoundsPage())
DemoConfiguration(buildRoute: (context) => MyLocationPage())
]),
Demo(
title: '限制地图显示范围',
category: DemoCategory.basic,
subtitle: '演示限定手机屏幕显示地图的范围',
slug: 'limit-map-bounds',
configurations: [
DemoConfiguration(buildRoute: (context) => MyLocationPage())
DemoConfiguration(buildRoute: (context) => LimitMapBoundsPage())
]),
];
}
Expand Down
11 changes: 11 additions & 0 deletions example/lib/pages/map/map_my_location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class MyLocationPage extends StatefulWidget {
}

class _BodyState extends State<MyLocationPage> {
AMapController? _mapController;

@override
void initState() {
super.initState();
Expand All @@ -35,6 +37,15 @@ class _BodyState extends State<MyLocationPage> {
circleStrokeColor: Colors.blue,
circleStrokeWidth: 1,
),
onLocationChanged: (loc) {
if (isLocationValid(loc)) {
print(loc);
_mapController?.moveCamera(CameraUpdate.newLatLng(loc.latLng));
}
},
onMapCreated: (controller) {
_mapController = controller;
},
);

return Container(
Expand Down
1 change: 1 addition & 0 deletions example/lib/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ class RouteConfig {
);
}
}
return null;
}
}
1 change: 1 addition & 0 deletions lib/amap_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ part 'src/amap_initializer.dart';
part 'src/amap_controller.dart';
part 'src/amap_widget.dart';
part 'src/amap_loader.dart';
part 'src/utils/location_utils.dart';
17 changes: 17 additions & 0 deletions lib/src/utils/location_utils.dart
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 2c3e525

Please sign in to comment.