Skip to content

Commit d22a437

Browse files
committed
revise REDME and Remove status listener
1 parent 025e008 commit d22a437

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

lib/samples/show_device_location_history/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ You can track device location history and display it as lines and points on the
1010

1111
## How to use the sample
1212

13-
Tap 'Start tracking' to start tracking your location, which will appear as points on the map. A line will connect the points for easier visualization. Tap 'Stop tracking' to stop updating the location history. This sample uses a simulated data source to allow the sample to be useful on desktop/non-mobile devices. To track a user's real position, use the `LocationDataSource` instead.
13+
Tap 'Start Tracking' to start tracking your location, which will appear as points on the map. A line will connect the points for easier visualization. Tap 'Stop Tracking' to stop updating the location history. This sample uses a simulated data source to allow the sample to be useful on desktop/non-mobile devices. To track a user's real position, use the `LocationDataSource` instead.
1414

1515
## How it works
1616

17-
1817
1. Create a graphics overlay to show each point and another graphics overlay for displaying the route line.
1918
2. Create a `SimulatedLocationDataSource` and initialize it with a polyline. Start the `SimulatedLocationDataSource` to begin receiving location updates.
2019
- NOTE: To track a user's real position, use `LocationDataSource` instead.
21-
3. Subscribe to the `LocationChanged` event to handle location updates.
20+
3. Subscribe to the `onLocationChanged` event to handle location updates.
2221
4. Every time the location updates, store that location, display a point on the map, and recreate the route line.
2322

2423
## Relevant API

lib/samples/show_device_location_history/show_device_location_history_sample.dart

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,17 @@ class ShowDeviceLocationHistorySample extends StatefulWidget {
2626
const ShowDeviceLocationHistorySample({super.key});
2727

2828
@override
29-
State<ShowDeviceLocationHistorySample> createState() => Configure();
29+
State<ShowDeviceLocationHistorySample> createState() =>
30+
_ShowDeviceLocationHistorySampleState();
3031
}
3132

32-
class Configure extends State<ShowDeviceLocationHistorySample>
33-
with SampleStateSupport {
33+
class _ShowDeviceLocationHistorySampleState
34+
extends State<ShowDeviceLocationHistorySample> with SampleStateSupport {
3435
// Create a controller for the map view.
3536
final _mapViewController = ArcGISMapView.createController();
3637
// A location data source to simulate location updates.
3738
final _locationDataSource = SimulatedLocationDataSource();
38-
// Subscriptions to listen for location status changes.
39-
StreamSubscription? _statusSubscription;
40-
// Subscriptions to listen for location changes.
39+
// Subscription to listen for location changes.
4140
StreamSubscription? _locationSubscription;
4241
// A GraphicsOverlay to display the location history polyline.
4342
final _locationHistoryLineOverlay = GraphicsOverlay();
@@ -56,7 +55,6 @@ class Configure extends State<ShowDeviceLocationHistorySample>
5655
void dispose() {
5756
_locationDataSource.stop();
5857
_locationSubscription?.cancel();
59-
_statusSubscription?.cancel();
6058
_locationHistoryLineOverlay.graphics.clear();
6159
_locationHistoryPointOverlay.graphics.clear();
6260

@@ -174,18 +172,10 @@ class Configure extends State<ShowDeviceLocationHistorySample>
174172
await rootBundle.loadString('assets/SimulatedRoute.json');
175173
final routeLine = Geometry.fromJsonString(routeLineJson) as Polyline;
176174
_locationDataSource.setLocationsWithPolyline(routeLine);
177-
_statusSubscription = _locationDataSource.onStatusChanged.listen((_) {
178-
// Redraw the screen when the LDS status changes
179-
setState(() {});
180-
});
181175

176+
// Start the location data source.
182177
try {
183-
// Start the location data source.
184178
await _locationDataSource.start();
185-
// Listen for location changes.
186-
_locationSubscription = _locationDataSource.onLocationChanged.listen(
187-
_handleLdsLocationChange,
188-
);
189179
} on ArcGISException catch (e) {
190180
if (mounted) {
191181
showDialog(
@@ -198,6 +188,13 @@ class Configure extends State<ShowDeviceLocationHistorySample>
198188
);
199189
}
200190
}
191+
192+
// Listen for location changes.
193+
if (_locationDataSource.status == LocationDataSourceStatus.started) {
194+
_locationSubscription = _locationDataSource.onLocationChanged.listen(
195+
_handleLdsLocationChange,
196+
);
197+
}
201198
}
202199

203200
// Handle location changes from the location data source.

0 commit comments

Comments
 (0)