現在の緯度経度のテキストを音声に変換したいのですが、現在の緯度経度を見つけるためのコードがありますが、Locationクラス内で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();
}}