我想以短信的形式发送当前位置。如何获得此位置并在Kotlin中作为消息发送?
emergency = (Button) findViewById(R.id.emergency);
emergency.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
GPStracker g = new GPStracker(getApplicationContext());
Location l = g.getLocation();
if (l != null){
double lat = l.getLatitude();
double lon = l.getLongitude();
String message="http://maps.google.com/maps?saddr="+lat+","+lon;
String number = "xxxxxxxx";
SmsManager smsManager = SmsManager.getDefault();
StringBuffer smsBody = new StringBuffer();
smsBody.append(Uri.parse(message));
android.telephony.SmsManager.getDefault().sendTextMessage(number, null, smsBody.toString(), null,null);
}
}
});