有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

安卓中google Map V2上的java语音导航

我正在写一个应用程序,我想引导用户从地图上的当前位置到一个特定点。我如何在安卓应用程序中使用Google Map API进行逐圈导航,并使用语音控制? 下面的代码绘制了到达目的地的路线,我想在位置改变时添加语音导航,比如左转右转

    public void drawPath(String result){

        try{

            final JSONObject json = new JSONObject(result);
            JSONArray routeArray = json.getJSONArray("routes");
            JSONObject routes = routeArray.getJSONObject(0);

            JSONObject overviewPolylines = routes.getJSONObject("overview_polyline");
            String encodedString = overviewPolylines.getString("points");

            Log.d("test: ", encodedString);
            List<LatLng> list = decodePoly(encodedString);
           // List<Direction> list2 = decodePoly(direction);
            LatLng last = null;
            for (int i = 0; i < list.size()-1; i++) {
                LatLng src = list.get(i);
                LatLng dest = list.get(i+1);
                last = dest;
                Log.d("Last latLng:", last.latitude + ", " + last.longitude );
                Polyline line = googleMap.addPolyline(new PolylineOptions().add( 
                        new LatLng(src.latitude, src.longitude), new LatLng(dest.latitude, dest.longitude))
                        .width(6)
                        .color(Color.RED));

            }
//          tts.speak(direction, TextToSpeech.QUEUE_FLUSH, null);
            if(googleMap != null){
                // create marker
                MarkerOptions marker = new MarkerOptions().position(new LatLng(last.latitude, last.longitude)).title("Hello Maps");

                // Changing marker icon
                marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.car));

                // adding marker
                googleMap.addMarker(marker);
                // check if map is created successfully or not
                 }
            Log.d("Last latLng:", last.latitude + ", " + last.longitude );
        }catch (JSONException e){
            e.printStackTrace();
        }
    } 

共 (0) 个答案