Reputation: 11
I want to display my motion on the google_maps_flutter, I know I can use the polylines feature, but how do I set initialCameraPosition so that all the lines are displayed on the current window? Here's how I look now, with some lines outside the window. enter image description here
// 运动轨迹
if((is_load == false) && (UI_Data.current_file!.movement_trajectory!.isNotEmpty))
{
for (var i = 0; i < UI_Data.current_file!.movement_trajectory!.length; i++)
{
MovementTrajectory data = UI_Data.current_file!.movement_trajectory![i];
point_list.add(LatLng(data.latitude, data.longitude));
}
}
// 连线
final Polyline polyline = Polyline(
polylineId: PolylineId("polyline_id_1"),
consumeTapEvents: true,
color: Colors.orange,
width: 2,
points: point_list,
onTap: () {
},
);
polylines[PolylineId("polyline_id_1")] = polyline;
GoogleMap(
gestureRecognizers: <Factory<OneSequenceGestureRecognizer>>{
Factory<OneSequenceGestureRecognizer>(
() => EagerGestureRecognizer(),
),
},
initialCameraPosition: CameraPosition(
target: LatLng(point_list[0].latitude, point_list[0].longitude),
zoom: 15,
),
myLocationEnabled: false,
zoomControlsEnabled: false,
// cameraTargetBounds: CameraTargetBounds(
// LatLngBounds(
// southwest: LatLng(22.731377, 113.800997),
// northeast: LatLng(22.750079, 113.836433),
// ),
// ),
polylines: Set<Polyline>.of(polylines.values),
markers: Set<Marker>.of(markers.values),
),
I tried using cameraTargetBounds, but I found that this option had something to do with zoom, and it sometimes showed up fine, but sometimes it didn't.
Upvotes: 1
Views: 43