현재 위도, 경도 텍스트를 음성으로 변환하고 싶습니다. 현재 위도, 경도를 찾기위한 코드가 있습니다. 위치 클래스 내 TextToSpeech 메소드를 초기화합니다. latLongString 만 있습니다. EX를 얻을 수 없습니다. 현재 위치는 lat = 1.222, long = 22.335입니다. 여기현재 위도, 경도 텍스트를 음성으로 말하는 법
내 코드 :
public class SpeakActivity extends Activity implements OnInitListener{
private TextToSpeech tts;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_speak);
LocationManager locationManager;
String context = Context.LOCATION_SERVICE;
locationManager = (LocationManager)getSystemService(context);
Criteria crta = new Criteria();
crta.setAccuracy(Criteria.ACCURACY_FINE);
crta.setAltitudeRequired(false);
crta.setBearingRequired(false);
crta.setCostAllowed(true);
crta.setPowerRequirement(Criteria.POWER_LOW);
String provider = locationManager.getBestProvider(crta, true);
// String provider = LocationManager.GPS_PROVIDER;
Location location = locationManager.getLastKnownLocation(provider);
tts = new TextToSpeech(this, this);
updateWithNewLocation(location);
}
public void speak(String text2say){
tts.speak(text2say, TextToSpeech.QUEUE_FLUSH, null);
}
@Override
public void onInit(int status) {
say("latLongString");
}
private void updateWithNewLocation(Location location) {
String latLongString;
TextView myLocation;
myLocation= (TextView) findViewById(R.id.myLocation);
if(location!=null) {
double lat = location.getLatitude();
double lon = location.getLongitude();
latLongString = "Lat:" + lat + "\nLong:" + lon;
}else{
latLongString="no location found";
}
myLocation.setText("Your current position is:\n" + latLongString);
speak(latLongString);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_speak, menu);
return true;
}
@Override
public void onDestroy() {
if (tts!= null) {
tts.stop();
tts.shutdown();
}
super.onDestroy();
}}
그러면 무엇을 했습니까? [이 예제를 보시라.] (http://www.androidhive.info/2012/01/android-text-to-speech-tutorial/) – Praveenkumar
Spk : 나는 당신의 링크 된 예제를 이미 보았다.하지만 나는 얻을 수 없었다. 내 위치 텍스트 위도, 경도로 연설. – Ram