2017-01-23 3 views
0

私の同僚は現在、私たちが取り組んでいる会社のために開発されているアプリに向けて方向転換を実施しています。私たちのどちらも進歩を遂げることはできませんでした。Mapboxを使用してアンドロイドアプリの方向指示で回る

彼はマップを作成するためにマップボックスを使用しています。私はmapboxを使用していないので、あまり役に立ちません。

彼は私たちにターン方向で向かうべきコードを実装していますが、何もしていないようです。

申し訳ありません私は古い質問を提起しているか、自分の状況をはっきりと述べていないが、これが最高です。我々は多くの検索を行ったが、私たちが見つけたものは役に立たないようだ。

ここでは、彼が使用しようとしているコードを示します。

private void getRoute(Waypoint origin, Waypoint destination) throws ServicesException { 

    MapboxDirections client = new MapboxDirections.Builder() 
      .setOrigin(origin) 
      .setDestination(destination) 
      .setProfile(DirectionsCriteria.PROFILE_DRIVING) 
      .setSteps(true) 
      // .setOverview(DirectionsCriteria.OVERVIEW_FULL) 
      .setInstructions(DirectionsCriteria.INSTRUCTIONS_TEXT) 
      .setAccessToken("pk.eyJ1IjoibnRyY3N2ZyIsImEiOiJCUmc4OHhjIn0.shHWdNg3Q32QUHJ1nOCs3A") 
      .build(); 

    client.enqueue(new retrofit.Callback<DirectionsResponse>() { 
     @Override 
     public void onResponse(Response<DirectionsResponse> response, Retrofit retrofit) { 
      // You can get the generic HTTP info about the response 
      Log.d(TAG, "Response code: " + response.code()); 
      if (response.body() == null) { 
       Log.e(TAG, "No routes found, make sure you set the right user and access token."); 
       return; 
      } else if (response.body().getRoutes().size() < 1) { 
       Log.e(TAG, "No routes found"); 
       return; 
      } 
     } 

     @Override 
     public void onFailure(Throwable t) { 
      Log.e(TAG, "Error: " + t.getMessage()); 
      Toast.makeText(MainActivity.this, "Error: " + t.getMessage(), Toast.LENGTH_SHORT).show(); 
     } 

     public void onResponse(Response<DirectionsResponse> call, Response<DirectionsResponse> response) { 
      // You can get the generic HTTP info about the response 
      Log.d(TAG, "Response code: " + response.code()); 
      if (response.body() == null) { 
       Log.e(TAG, "No routes found, make sure you set the right user and access token."); 
       return; 
      } else if (response.body().getRoutes().size() < 1) { 
       Log.e(TAG, "No routes found"); 
       return; 
      } 

      drawRoute(currentRoute); 
     } 


     private void drawRoute(DirectionsRoute route) { 
      // Convert LineString coordinates into LatLng[] 
      LineString lineString = LineString.fromPolyline(route.getGeometry(), Constants.OSRM_PRECISION_V5); 
      List<Position> coordinates = lineString.getCoordinates(); 
      LatLng[] points = new LatLng[coordinates.size()]; 
      for (int i = 0; i < coordinates.size(); i++) { 
       points[i] = new LatLng(

         coordinates.get(i).getLatitude(), 
         coordinates.get(i).getLongitude()); 
      } 

      Polyline polyline = mMapboxMap.addPolyline(new PolylineOptions() 
        .add(points) 
        .color(Color.RED) 
        .width(5)); 
      directionsOn = true; 


     } 

ご協力いただければ幸いです。

ありがとうございます。

答えて

0

Mapbox JavaにあるDirections v4からv5に変更することを強くおすすめします。スイッチを設定したら、当社のウェブサイトにあるthis exampleを解決することができます。正しい順序で座標を渡していることを確認してください。longitudeが最初に指定され、次にlatitudeが続きます。

0

親愛なる友人のマップボックスは、サンプルコードスニペットの詳細なドキュメントも提供しています。 地図ターンのナビゲーション文書をたどって、私の要件のために働くアプリケーションをビルドしました。

問題が発生した場合は、リンク先に連絡してください。

リンク:https://www.mapbox.com/android-docs/navigation/overview/navigation-ui/

ここでは、ターン機能によってmapboxターンをカスタマイズするNavigationViewコンポーネントを使用することができます。

関連する問題