如何在Android中获取某人的纬度和经度?

Posted

技术标签:

【中文标题】如何在Android中获取某人的纬度和经度?【英文标题】:How can I get the lattitude and longitude of someone in Android? 【发布时间】:2017-01-25 01:16:44 【问题描述】:

其实我想计算两个用户坐标之间的距离。有没有什么地方适合我开始在 android 上使用 GPS 功能,或者有一个很好的例子来说明如何使用 GPS?

我不想要任何深入的东西,实际上只是如何检索和使用当前的 GPS 坐标。我想从简单开始,然后从那里开始。

【问题讨论】:

【参考方案1】:

要获取纬度,请从这里开始参考:

https://developer.android.com/reference/android/location/Location.html#getLatitude()

示例代码(未编译或测试):

LocationManager locmgr=(LocationManager)ctx.getSystemService(Context.LOCATION_SERVICE);
Location l=locmgr.getLastKnownLocation(LocationManager.GPS_PROVIDER);
double latitude = l.getLatitude();

【讨论】:

以上是关于如何在Android中获取某人的纬度和经度?的主要内容,如果未能解决你的问题,请参考以下文章