Skip to content Skip to sidebar Skip to footer

How Can I Use My Gps Coordinates Via Sms-body Android

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(loca

Solution 1:

i used this code in my previous application

privatevoidsendSMS() {
    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();
    }
}

and it wont matter much but getCurrentLocationFromGPS() was like

privatevoidgetCurrentLocationFromGPS() {
    //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();
    }
}

Post a Comment for "How Can I Use My Gps Coordinates Via Sms-body Android"