2013-08-26 59 views
2

我是一名新的android开发者。 我想发送包含我当前位置的短信。我知道如何获得我的位置坐标。但是我想要的是发送像URL一样,用户可以打开并查看我的位置(例如:使用wa you可以分享您的位置,我也可以使用Google地图应用)。我尝试了谷歌地图API,但我没有找到像生成URL的选项。通过短信发送我当前所在的位置 - Android

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

谢谢大家!

+1

,如果你知道如何获得位置坐标试试,然后先在你身边的链接,然后尝试通过短信发送。 –

+0

但是如何才能做到这一点? – nanoalvarez

回答

1

指得到它使用SMS API发送位置后,该链接 http://javapapers.com/android/get-current-location-in-android/

+0

谢谢你的帮助。但我知道如何获得我的位置。我不知道的是如何发送一个URL与我的位置和我发送我的位置的人能够打开该网址。例如,当人点击Url时,地图上就会显示地图。点击并发送到我的位置谷歌地图。 – nanoalvarez

6

我想这是你需要的。

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); 
} 

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

我开发了一个应用程序,它使用位置功能并在地图中显示。在谷歌播放看到它。

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

+0

您只需修改基本链接,如下所示: smsBody.append(“http://maps.google.com/maps?q=”); – hhyari

+0

@hhyari你能告诉我它是如何工作的,如果我使用一个字符串短信 – Abhishek

2
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); 

你不得不解析字符串URI。它为我工作