Android 按时间间隔发送纬度和经度,Location 对象
我看过其他一些问题和教程,但我没有得到我想要的东西
我正在尝试以这种格式获取纬度和经度
latitude = 40.769134 , longitude = -73.960905
我实现了这个课程,它需要我的全局变量纬度和经度(它们是长数据类型)
class GpsListener implements LocationListener{
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
latitude = location.getLatitude();
longitude = location.getLongitude();
//float speed = location.getSpeed();
checkin();
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
// TODO Auto-generated method stub
}
}
我在这里查看了其他教程,并注意到人们使用 LocationManager
类与我的接口进行交互LocationListener
但我真正需要做的就是使用 Location
对象,因为我的类 GpsListener.onLocationChanged(.. )
需要一个位置对象,但是您能否给出有关如何使用位置对象或如何简单地获取经度和纬度的示例或指导?
我只是将纬度和经度传递给服务器,因此我不需要对 GPS 模块执行任何其他操作,我的 checkin()
函数使服务器调用
I've looked at a few other questions and tutorials but I'm not getting what I'm looking for
I am trying to get the latitude and longitude in this format
latitude = 40.769134 , longitude = -73.960905
I implemented this class which takes my global variables latitude and longitude (they are long data types)
class GpsListener implements LocationListener{
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
latitude = location.getLatitude();
longitude = location.getLongitude();
//float speed = location.getSpeed();
checkin();
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
// TODO Auto-generated method stub
}
}
I've looked at other tutorials here and notice that people use the LocationManager
class to interface with my LocationListener
but all I really need to do is use a Location
object becuase my class GpsListener.onLocationChanged(.. )
needs a location object, but can you give an example or guidance on how to use the location object or how to simply get this longitude and latitude?
I am simply passing the latitude and longitude to a server so I dont need to do anything else with the GPS module, my checkin()
function makes the server call
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否试图避免使用 LocaitonManager ?
如果您只想使用一次,我想您可以在收到位置后取消注册所有内容。但也许您想确保精度在 x 米等范围内。
are you trying to avoid using the LocaitonManager?
if you just want to use it once, I suppose you could deregister everything after receiving a location. But maybe you want to make sure the accuracy is within x meters etc..