我正在编写一个应用程序,我想引导用户从地图上的当前位置到特定点。如何在我的Android应用程序中使用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();
}
}