将当前用户纬度,经度转换为TextToSpeech

时间:2012-08-13 05:19:36

标签: android gps text-to-speech

我有一个用于查找当前位置的代码。然后我在我的代码中初始化TextToSpeech。但是我无法将当前位置文本转换为语音。如何在TextToSpeech中插入我当前的位置纬度,经度。

mycode的:

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); 
        updateWithNewLocation(location);

        tts = new TextToSpeech(this, this);


    }

    public void say(String text2say){

              tts.speak(text2say, TextToSpeech.QUEUE_FLUSH, null);

            }

    @Override

       public void onInit(int status) {

          say("latLongString");    

       }



       @Override

       public void onDestroy() {

          if (tts!= null) {

             tts.stop();

             tts.shutdown();

          }   

          super.onDestroy();

       }



    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);
        say(latLongString);

    }

0 个答案:

没有答案