Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
5.0 kB
4
Indexable
Never
import 'dart:io' show Platform;

import 'package:flutter/foundation.dart';
import 'package:url_launcher/url_launcher.dart';

class MapsUtils {
  /// [Görünüm: Belirtilen Koordinat Haritada Pinlenmiş]
  /// [Android] [Google Maps URLs] [Location Search (Konum Arama)]
  /// [query], [Latitude] (Enlem) ve [Longitude] (Boylam) ile gösterin:
  /// [https://www.google.com/maps/search/?api=1&query=$query&center$latitude,$longitude]
  /// Example: https://www.google.com/maps/search/?api=1&query=Erzurum+Atatürk+Evi&center39.906635,41.268963

  /// [Apple] [Apple Maps URLs] [Location Search (Konum Arama)]
  /// Data URI Scheme: Haritaya verilen;
  /// [Q]uery, [L]atitude (Enlem) ve [L]ongitude (Boylam) ile gösterin:
  /// [https://maps.apple.com/?q=$query?ll=$latitude,$longitude]
  /// Example: https://maps.apple.com/?q=Erzurum+Atatürk+Evi?ll=39.906635,41.268963

  static Future<void> launchShowOnMap(
      {String query, double latitude, double longitude}) async {
    if (await canLaunch(urlShowOnMap(query, latitude, longitude))) {
      await launch(urlShowOnMap(query, latitude, longitude));
    } else {
      throw "Could not launch $urlShowOnMap";
    }
  }

  ///[Görünüm: Belirtilen Koordinata Arabayla/Sürüş Yol Tarifi Hazırlanmış]
  /// [Android] [Google Maps URLs] [Directions-Car(Yol Tarifi: Araba)]
  /// [destination] (Varış), [Latitude] (Enlem), [Longitude] (Boylam) ve
  /// [travelmode=driving]/walking/bicycling/transit
  /// (Seyahat Yöntemi = Araba/Yürüme/Bisiklet/Toplu Taşıma) ile
  /// [https://www.google.com/maps/dir/?api=1&destination=$latitude,$longitude&travelmode=driving]
  /// Example: https://www.google.com/maps/dir/?api=1&destination=41.02211,29.0120804&travelmode=driving
  /// Not: Sonuna [&dir_action=navigate] parametresi eklenirse navigasyonu [rota önizlemesi] ile başlatır

  /// [Apple] [Apple Maps URLs] [Directions-Car(Yol Tarifi: Araba)]
  /// [daddr](Varış), [Latitude] (Enlem), [Longitude] (Boylam) ve
  /// [dirflg=d] (Sürüş) /[dirflg=w] (Yürüme) / [dirflg=t] (Toplu Taşıma)   ile
  /// [https://maps.apple.com/?daddr=$latitude,$longitude&dirflg=d]
  /// Example: https://maps.apple.com/?daddr=39.906635,41.268963&dirflg=d

  static Future<void> launchDriving({double latitude, double longitude}) async {
    if (await canLaunch(urlDriving(latitude, longitude))) {
      await launch(urlDriving(latitude, longitude));
    } else {
      throw "Could not launch $urlDriving";
    }
  }

  static Future<void> launchWalking({double latitude, double longitude}) async {
    if (await canLaunch(urlWalking(latitude, longitude))) {
      await launch(urlWalking(latitude, longitude));
    } else {
      throw "Could not launch $urlWalking";
    }
  }

  static String urlShowOnMap(String query, double latitude, double longitude) {
    String baseGoogleUrlMap = "https://www.google.com/maps/search/?api=1";
    String baseAppleUrlMap = "https://maps.apple.com/";
    if (!kIsWeb) {
      if (Platform.isAndroid) {
        if (query != "") {
          return Uri.encodeFull(
              "$baseGoogleUrlMap&query=$query&center$latitude,$longitude");
        } else {
          return Uri.encodeFull("$baseGoogleUrlMap&query=$latitude,$longitude");
        }
      } else if (Platform.isIOS) {
        if (query != "") {
          return Uri.encodeFull(
              "$baseAppleUrlMap?q=$query?ll=$latitude,$longitude");
        } else {
          return Uri.encodeFull("$baseAppleUrlMap?sll=$latitude,$longitude");
        }
      }
    }
    return Uri.encodeFull(
        "$baseGoogleUrlMap&query=$query&center$latitude,$longitude");
  }

  static String urlDriving(double latitude, double longitude) {
    String baseGoogleUrlDriving =
        "https://www.google.com/maps/dir/?api=1&destination";
    String baseAppleUrlDriving = "https://maps.apple.com/?daddr";
    if (!kIsWeb) {
      if (Platform.isAndroid) {
        return Uri.encodeFull(
            "$baseGoogleUrlDriving=$latitude,$longitude&travelmode=driving");
      } else if (Platform.isIOS) {
        return Uri.encodeFull(
            "$baseAppleUrlDriving=$latitude,$longitude&dirflg=d");
      }
    }
    return Uri.encodeFull(
        "$baseGoogleUrlDriving=$latitude,$longitude&travelmode=driving");
  }

  ///[Görünüm: Belirtilen Koordinata Yürüme/Yaya Yol Tarifi Hazırlanmış]

  static String urlWalking(double latitude, double longitude) {
    String baseGoogleUrlWalking =
        "https://www.google.com/maps/dir/?api=1&destination";
    String baseAppleUrlWalking = "https://maps.apple.com/?daddr";
    if (!kIsWeb) {
      if (Platform.isAndroid) {
        return Uri.encodeFull(
            "$baseGoogleUrlWalking=$latitude,$longitude&travelmode=walking");
      } else if (Platform.isIOS) {
        return Uri.encodeFull(
            "$baseAppleUrlWalking=$latitude,$longitude&dirflg=w");
      }
    }
    return Uri.encodeFull(
        "$baseGoogleUrlWalking=$latitude,$longitude&travelmode=walking");
  }
}