패키지, 저장소 및 앱 카테고리 검색

GitHub 저장소bienvenuelisis/google_maps_directions

google_maps_directions

Google Maps 방향 API를 사용하여 두 지점 사이의 거리, 소요 시간 및 최단 경로/구간 계산

google_maps_directions 프로젝트 이미지
스타
6
포크
3
최근 푸시(UTC)
2023. 7. 18.
프로젝트 상태
활성

원본 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 ↗