requestMyLocationLatLng method

  1. @override
Future<LatLng?> requestMyLocationLatLng()
override

Implementation

@override
Future<LatLng?> requestMyLocationLatLng() async {
  try {
    // Null whenever there is no fix yet - including every call made before
    // the style finished loading, since the location component only exists
    // from then on. Callers are expected to retry rather than treat it as an
    // error.
    final reply = await _channel
        .invokeMapMethod<dynamic, dynamic>('locationComponent#getLastLocation');
    if (reply == null) return null;
    var latitude = 0.0;
    var longitude = 0.0;
    if (reply.containsKey('latitude') && reply['latitude'] != null) {
      latitude = double.parse(reply['latitude'].toString());
    }
    if (reply.containsKey('longitude') && reply['longitude'] != null) {
      longitude = double.parse(reply['longitude'].toString());
    }
    return LatLng(latitude, longitude);
  } on PlatformException catch (e) {
    return Future.error(e);
  }
}