検索
ホームページJava&#&チュートリアルGoogle Maps API v2 を使用してターンバイターン方式のルート案内を取得するにはどうすればよいですか?

How to Get Turn-by-Turn Driving Directions Using Google Maps API v2?

Google Maps API v2 を使用して運転ルートを取得する

2 つの場所間の運転ルートを取得することは、多くの地図アプリケーションの共通の要件です。ただし、指定したコードは、ターンバイターンの道順を提供するのではなく、ポイント間に直線を描画するだけです。

Android GoogleDirection ライブラリを使用したソリューション

運転ルートを取得するには、akexorcist によって最近リリースされたライブラリである Android GoogleDirectionLibrary を利用できます。このライブラリを使用した変更されたコード スニペットは次のとおりです。

import com.akexorcist.googledirection.DirectionCallback;
import com.akexorcist.googledirection.GoogleDirection;
import com.akexorcist.googledirection.model.Direction;
import com.akexorcist.googledirection.model.Leg;
import com.akexorcist.googledirection.model.Route;
import com.akexorcist.googledirection.util.DirectionConverter;

...

// Replace with your API key
String apiKey = "YOUR_API_KEY";

GoogleDirection.withServerKey(apiKey)
        .from(new LatLng(12.917745600000000000,77.623788300000000000))
        .to(new LatLng(12.842056800000000000,7.663096499999940000))
        .execute(new DirectionCallback() {
            @Override
            public void onDirectionSuccess(Direction direction, String rawBody) {
                if (direction.isOK()) {
                    Route route = direction.getRouteList().get(0);
                    Leg leg = route.getLegList().get(0);
                    
                    // Draw the path (Polylines)
                    List<latlng> directionPositionList = DirectionConverter.decodePoly(leg.getPolylinePoint());
                    Polyline line = mMap.addPolyline(new PolylineOptions()
                            .addAll(directionPositionList)
                            .width(5)
                            .color(Color.RED));
                    
                    // Display turn-by-turn instructions
                    String[] instructions = DirectionConverter.provideInstructionList(leg);
                    for (String instruction : instructions) {
                        Log.d("Direction", instruction);
                    }
                } else {
                    // Handle error
                }
            }

            @Override
            public void onDirectionFailure(Throwable t) {
                // Handle error
            }
        });</latlng>

この変更されたコードを使用すると、ターンバイターンの指示を含む、2 つの場所間の運転ルートを取得できるようになります。

以上がGoogle Maps API v2 を使用してターンバイターン方式のルート案内を取得するにはどうすればよいですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

VSCode Windows 64 ビットのダウンロード

VSCode Windows 64 ビットのダウンロード

Microsoft によって発売された無料で強力な IDE エディター

MantisBT

MantisBT

Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強力な PHP 統合開発環境

Dreamweaver Mac版

Dreamweaver Mac版

ビジュアル Web 開発ツール

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

このプロジェクトは osdn.net/projects/mingw に移行中です。引き続きそこでフォローしていただけます。 MinGW: GNU Compiler Collection (GCC) のネイティブ Windows ポートであり、ネイティブ Windows アプリケーションを構築するための自由に配布可能なインポート ライブラリとヘッダー ファイルであり、C99 機能をサポートする MSVC ランタイムの拡張機能が含まれています。すべての MinGW ソフトウェアは 64 ビット Windows プラットフォームで実行できます。