我怎样才能通过sms-body android来使用我的GPS坐标 [英] How can I use my gps coordinates via sms-body android

查看:191
本文介绍了我怎样才能通过sms-body android来使用我的GPS坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须通过短信发送我的GPS坐标,如何获取SMS正文中的经度和纬度值?
我尝试了一些东西,但我不能使用+ @ id / lat或+ String.valueOf(location.getLongitude()in intent.putExtra(sms_body,将会有经度和纬度值..) ;

I have to send my GPS coordinates via SMS, How can I take the latitude and longitude values in SMS body? I tried something but i cant make it with +@id/lat or +String.valueOf(location.getLongitude() in intent.putExtra("sms_body","there would be latitude and longitude values..");

这里是SmsActivity.java

Here is the SmsActivity.java

public class SmsActivity extends MainActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button button1 = (Button) findViewById(R.id.button1);
        EditText editText = (EditText)findViewById(R.id.telNo);

        final String telNo = editText.getText().toString();
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Uri uri = Uri.parse("smsto:" +telNo);
                Intent intent = new Intent(Intent.ACTION_SENDTO,uri);
                intent.putExtra("sms_body","there would be latitude and longitude values..");
                startActivity(intent);

                finish();
            }
        });    
    };
}

以下是MainActivity.java

Here is the MainActivity.java

    latitude = (TextView) findViewById(R.id.lat);
    longitude = (TextView) findViewById(R.id.lon);
    provText = (TextView) findViewById(R.id.prov);
    choice = (TextView) findViewById(R.id.choice);
    fineAcc = (CheckBox) findViewById(R.id.fineAccuracy);
    choose = (Button) findViewById(R.id.chooseRadio);

    // Get the location manager
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    // Define the criteria how to select the location provider
    criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_COARSE); //default

    // user defines the criteria
    choose.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if(fineAcc.isChecked()){
                criteria.setAccuracy(Criteria.ACCURACY_FINE);
                choice.setText("fine accuracy selected");
            }else {
                criteria.setAccuracy(Criteria.ACCURACY_COARSE);
                choice.setText("coarse accuracy selected");
            }
        }
    });
    criteria.setCostAllowed(false);
    // get the best provider depending on the criteria
    provider = locationManager.getBestProvider(criteria, false);

    // the last known location of this provider
    Location location = locationManager.getLastKnownLocation(provider);

    mylistener = new MyLocationListener();

    if (location != null) {
        mylistener.onLocationChanged(location);
    } else {
        // leads to the settings because there is no last known location
 //       Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
 //       startActivity(intent);
    }
    // location updates: at least 1 meter and 200millsecs change
    locationManager.requestLocationUpdates(provider, 200, 1, mylistener);
}
private class MyLocationListener implements LocationListener {

    @Override
    public void onLocationChanged(Location location) {
        // Initialize the location fields
        latitude.setText("Latitude: "+String.valueOf(location.getLatitude()));
        longitude.setText("Longitude: "+String.valueOf(location.getLongitude()));

如何获取SMS正文中的经度和纬度值?

How can I take the latitude and longitude values in SMS body?

推荐答案

我在之前的应用程序中使用了此代码

i used this code in my previous application

private void sendSMS() {
    try {
        if(phonenumber != null && !phonenumber.isEmpty()) {
            getCurrentLocationFromGPS();

            String locstring=latitude+","+longitude;
            String mapsurl= "http://maps.google.com/maps?q=" + locstring;

            SmsManager sms = SmsManager.getDefault();
            sms.sendTextMessage(phonenumber, null, "I need Help urgent.. I am at this location: " + mapsurl, null, null);
            Toast.makeText(this, "Help message has been sent", Toast.LENGTH_LONG).show();
        }

    } catch(Exception e) {
        e.printStackTrace();
    }
}




但是getCurrentLocationFromGPS()就像

and it wont matter much but getCurrentLocationFromGPS() was like



    private void getCurrentLocationFromGPS() {
    //gps = new GPSTracker(HelpClickActivity.this);
    if(gps.canGetLocation()){
        latitude = gps.getLatitude();
        longitude = gps.getLongitude();

        dist1=distFrom(latitude, longitude, latitude1, longitude1);
        dist2=distFrom(latitude, longitude, latitude2, longitude2);

        Toast.makeText(this, "Dist1: " + dist1 + "kms \nDist2: " + dist2 + "kms", Toast.LENGTH_LONG).show();

        calculatemin(dist1,dist2);
    }else{
        gps.showSettingsAlert();
    }
}

这篇关于我怎样才能通过sms-body android来使用我的GPS坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆