通过短信发送我当前的位置 - Android

nan*_*rez 2 url sms gps android location

我是一个新的Android开发人员.我想发送包含我当前位置的短信.我知道如何获得我的位置坐标.但我想要的是像URL一样发送,用户可以打开并查看我的位置(例如:使用waze,您可以分享您的位置,我认为也可以使用谷歌地图应用程序).我尝试使用谷歌地图API,但我没有找到生成URL的选项.

任何人都可以提出一些想法吗?或者API?

感谢大家!!!

小智 7

我想这就是你需要的.

public void sendLocationSMS(String phoneNumber, Location currentLocation) {
    SmsManager smsManager = SmsManager.getDefault();
    StringBuffer smsBody = new StringBuffer();
    smsBody.append("http://maps.google.com?q="); 
    smsBody.append(currentLocation.getLatitude());
    smsBody.append(",");
    smsBody.append(currentLocation.getLongitude());
    smsManager.sendTextMessage(phoneNumber, null, smsBody.toString(), null, null);
}
Run Code Online (Sandbox Code Playgroud)

我会使用地图叠加而不是默认地图.

我开发了一个使用位置功能并在地图中显示的应用程序.在Google Play上看到它.

"Wherez U" https://play.google.com/store/apps/details?id=com.kabhos.android.apps.knowmylocation


小智 5

String uri = "http://maps.google.com/maps?saddr=" + currentLocation.getLatitude()+","+currentLocation.getLongitude();

    SmsManager smsManager = SmsManager.getDefault();
    StringBuffer smsBody = new StringBuffer();
    smsBody.append(Uri.parse(uri)); `
smsManager.sendTextMessage(phonenumber, null, smsBody.toString(), null, null);
Run Code Online (Sandbox Code Playgroud)

你必须将该字符串解析为 uri。这对我有用