Google Maps API v2 で運転ルートを描画するにはどうすればよいですか?
Google Maps API v2 を使用した運転ルートの描画
この質問では、ユーザーは Google を使用して 2 つの地理座標間の運転ルートを描画しようとしていますマップ API v2。ただし、提供されるコードは、実際の走行ルートではなく、単に直線を描画するだけです。
望ましい結果を得るために、ユーザーは Google の Directions API と連携するライブラリを利用できます。そのようなライブラリの 1 つが「Android-GoogleDirectionLibrary」(https://github.com/akexorcist/Android-GoogleDirectionLibrary) です。このライブラリを使用すると、開発者は運転ルートを JSON データとして簡単に取得でき、地図上にポリラインとしてプロットできます。
このライブラリを使用するには、次の手順に従います。
-
ライブラリを Gradle ビルド ファイルに追加します:
dependencies { ... implementation 'com.akexorcist:googledirectionlibrary:1.3.5' ... }
ログイン後にコピー -
Google Maps API と Directions API クライアントを初期化します:
<code class="java">// Initialize the Google Maps API GoogleMap mMap = ... // Initialize the Directions API client DirectionsClient directionsClient = Directions.newDirectionsClient(getApplicationContext());</code>
ログイン後にコピー -
出発地と目的地の座標を指定します:
<code class="java">LatLng origin = new LatLng(12.917745600000000000, 77.623788300000000000); LatLng destination = new LatLng(12.842056800000000000, 7.663096499999940000);</code>
ログイン後にコピー -
ルート リクエストを作成して実行します:
<code class="java">DirectionsApiRequest request = new DirectionsApiRequest.Builder() .origin(origin) .destination(destination) .build(); directionsClient.getDirectionsAsync(request, new DirectionListener() { @Override public void onDirectionRetrieved(DirectionsResult result) { // Handle the response from the Directions API PolylineOptions options = new PolylineOptions() .addAll(result.getRouteList().get(0).getOverviewPolyline().getDecodedPath()); mMap.addPolyline(options); } @Override public void onDirectionFailed(DirectionException e) { // Handle any errors } });</code>
ログイン後にコピー
これを利用しますこのアプローチを使用すると、ユーザーは地図上の 2 点間の運転方向を正確に描画し、ルートが実際の道路と一致していることを確認できます。
以上がGoogle Maps API v2 で運転ルートを描画するにはどうすればよいですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

ホットAIツール

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

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

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

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

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック







