openMapForLocation function

Future openMapForLocation(
  1. BuildContext context,
  2. IPhysicalLocation sunnyPlace
)

Implementation

Future openMapForLocation(
    BuildContext context, IPhysicalLocation sunnyPlace) async {
  String? googlePlaceId = sunnyPlace.googlePlaceId;
  if (googlePlaceId == null) {
    GooglePlaceId? lookupResult;
    await SunnyHud.spinner(context, "Calculating location",
        operation: () async {
      lookupResult = await lookupAddressInGoogle(sunnyPlace);
      return lookupResult;
    }).value;
    googlePlaceId = lookupResult?.placeId;
  }

  final details = await lookupPlaceInGoogle(googlePlaceId);
  illegalState("Need to fix this");
  // sunnyPlace.placeDetails = details;

  if (details == null) {
    await SunnyHud.error(context, "Unable to generate map to this location")
        .value;
    return;
  }

  final geo = details.geometry!.location;

  if (infoX.isIOS) {
    final url = "https://maps.apple.com/?q=${geo.lat},${geo.lng}";
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      SunnyHud.error(context, "Unable to show a map at this time");
    }
  } else {
    SunnyHud.info(context, "Coming soon");
  }
}