पैकेज, रिपॉज़िटरी और ऐप श्रेणियाँ खोजें

GitHub रिपॉज़िटरीbienvenuelisis/google_maps_directions

google_maps_directions

Google Maps दिशानिर्देश API के साथ दो बिंदुओं के बीच दूरी, अवधि और सबसे छोटा मार्ग/खंड की गणना करें

google_maps_directions प्रोजेक्ट कवर
स्टार
6
फ़ोर्क
3
अंतिम पुश (UTC)
18 जुल॰ 2023
प्रोजेक्ट स्थिति
सक्रिय

मूल README

यह अंग्रेज़ी मूल स्नैपशॉट है। नवीनतम सामग्री GitHub पर देखें।

Get directions shortest route/leg between two points & calculate distances, durations with Google_Maps Directions API

Documentation française accessible ici.

Features

  • Get directions between two points.
  • Calculate distance or duration (corresponding to shortest route distance /duration evaluation) between two points.
  • Get shortest route between/leg two points.

Getting started

  • AddressPoint : Object with latitude and longitude.
  • DirectionRoute : Path on foot, motorcycle, train, or car between two points.

Usage

You need to have a valid Google Maps Routes API Key.

const String googleAPIKey = "GOOGLE_API_KEY";

//You can init the Package with this API_Key so you don't have to pass it as an argument to it's methods.

GoogleMapsDirections.init(googleAPIKey: googleAPIKey);
Directions
import "package:google_maps_directions/google_maps_directions.dart" as gmd;

...

Directions directions = await getDirections(
        p1.lat,
        p1.lng,
        p2.lat,
        p2.lng,
        language: "fr_FR",
      );

DirectionRoute route = directions.shortestRoute;

You can draw a route between the two addresses on a Map using google_maps_flutter and flutter_polyline_points packages.

import 'package:flutter_polyline_points/flutter_polyline_points.dart';
import 'package:google_maps_directions/google_maps_directions.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

...

DirectionRoute route = directions.shortestRoute;

List<LatLng> points = PolylinePoints().decodePolyline(route.overviewPolyline.points)
   .map((point) => LatLng(point.latitude, point.longitude))
                 .toList();

List<Polyline> polylines = [
 Polyline(
            width: 5,
            polylineId: PolylineId("UNIQUE_ROUTE_ID"),
            color: Colors.green,
            points: points,
          ),
];

...

@override
 Widget build(BuildContext context) {
    return Scaffold(
 body : GoogleMap(
              polylines: Set.of(polylines),
              ...
            ),
       );
}

You can also give indications for each stage of a route. A more complete demonstration is provided in example directory.

import 'package:google_maps_directions/google_maps_directions.dart';

... 


DirectionRoute route = directions.shortestRoute;

DirectionLegStep firstRouteLegStep = route.shortestLeg.steps.first;
print(firstRouteLegStep.htmlInstructions); //At the roundabout, take the exit onto route National 1.
print(firstRouteLegStep.maneuver); //roundabout-right.

Distance
import "package:google_maps_directions/google_maps_directions.dart" as gmd;

DistanceValue distanceBetween = await gmd.distance(9.2460524, 1.2144565, 6.1271617, 1.2345417, googleAPIKey : googleAPIKey); //gmd.distance(9.2460524, 1.2144565, 6.1271617, 1.2345417) or without passing the API_KEY if the plugin is already initialized with it's value.

int meters = distanceBetween.meters // await gmd.distanceInMeters(9.2460524, 1.2144565, 6.1271617, 1.2345417, googleAPIKey : googleAPIKey);

String textInKmOrMeters = distanceBetween.text // await gmd.distanceText(9.2460524, 1.2144565, 6.1271617, 1.2345417, googleAPIKey : googleAPIKey);
Duration
import "package:google_maps_directions/google_maps_directions.dart" as gmd;

DurationValue durationBetween = await gmd.duration(9.2460524, 1.2144565, 6.1271617, 1.2345417, googleAPIKey : googleAPIKey);

int seconds = durationBetween.seconds//await gmd.durationInSeconds(9.2460524, 1.2144565, 6.1271617, 1.2345417, googleAPIKey : googleAPIKey);

String durationInMinutesOrHours = gmd.durationBetween.text // await gmd.durationText(9.2460524, 1.2144565, 6.1271617, 1.2345417, googleAPIKey : googleAPIKey);

Issues | Features requests

Feel free to submit issues, suggestions or features requests on this package issues tracker.

Kokou Bienvenu AGBAVON GitHub avatar
GitHub लेखक

Kokou Bienvenu AGBAVON ↗

Creating mobile apps like works of art...

AuthenticDev
भाषाएँDartKotlin

श्रेणियाँ

इस रिपॉज़िटरी के पैकेज

उपयोग की गई निर्भरताएँ

निर्भरता सूची 3 आइटम

अपने प्रोजेक्ट के लिए रिपॉज़िटरी कैसे चुनें?

उपयोग के अनुसार छाँटें, गतिविधि की तुलना करें और अपनाने से पहले मूल प्रोजेक्ट की आवश्यकताएँ जाँचें।

  1. नाम, लेखक या विवरण से खोजें और तकनीकी विषय से परिणाम सीमित करें।
  2. स्टार, फ़ोर्क और हाल के पुश की तुलना करें। स्टार रुचि दर्शाते हैं, गुणवत्ता की गारंटी नहीं।
  3. उपयोग से पहले GitHub पर README, लाइसेंस और Issues जाँचें।

स्रोत और रखरखाव

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗