Method FromStreamCreator
FromStreamCreator(Func<NmeaLocationDataSource, Task<Stream>>, Func<NmeaLocationDataSource, Task>)
Returns a Nmea
Declaration
public static NmeaLocationDataSource FromStreamCreator(Func<NmeaLocationDataSource, Task<Stream>> onStart, Func<NmeaLocationDataSource, Task> onStop = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
onStart | This method is called when the datasource starts, and should return a System. |
System. |
onStop | This method is called when the datasource stops, and can be used to clean up resources. |
Returns
Type | Description |
---|---|
Nmea |
An NmeaLocationDataSource. |
Remarks
This helper method is useful for only creating a datasource stream on start and stop, rather than always have the stream running regardless of the datasource state.
var port = new System.IO.Ports.SerialPort("COM1", 9600);
NmeaLocationDataSource serialPortDatasource = NmeaLocationDataSource.FromStreamCreator(
onStart: (ds) =>
{
port.Open();
return Task.FromResult(port.BaseStream);
},
onStop: (ds) =>
{
port.Close();
return Task.CompletedTask;
}
);
MyMapView.LocationDisplay.DataSource = serialPortDatasource;
MyMapView.LocationDisplay.IsEnabled = true; // This will trigger onStart to get called
As an alternative to this approach, you can also subclass Nmea
Applies to
Platforms and versions
Target | Versions |
---|---|
.NET Windows | 100.13 - 200.6 |
.NET Android | 200.2 - 200.6 |
.NET iOS | 200.0 - 200.6 |
.NET Framework | 100.10 - 200.6 |
Xamarin.Android | 100.10 - 100.14 |
Xamarin.iOS | 100.10 - 100.15 |
UWP | 100.10 - 200.6 |