是否有任何方法可以仅使用android服务检索当前gps坐标
我必须创建一个android服务,它需要获取当前的GPS坐标,并通过计时器每隔一分钟显示一次祝酒词。除非通过仿真器控件手动发送,否则我似乎无法获取坐标。我已经有一个服务,每分钟运行一个计时器来显示祝酒词“你好”。但到目前为止,我还没有找到任何解决方案是否有任何方法可以仅使用android服务检索当前gps坐标,android,gps,android-service,coordinates,Android,Gps,Android Service,Coordinates,我必须创建一个android服务,它需要获取当前的GPS坐标,并通过计时器每隔一分钟显示一次祝酒词。除非通过仿真器控件手动发送,否则我似乎无法获取坐标。我已经有一个服务,每分钟运行一个计时器来显示祝酒词“你好”。但到目前为止,我还没有找到任何解决方案 public static final long NOTIFY_INTERVAL = 60 * 1000; // 60 seconds // run on another Thread to avoid crash private Handler
public static final long NOTIFY_INTERVAL = 60 * 1000; // 60 seconds
// run on another Thread to avoid crash
private Handler mHandler = new Handler();
// timer handling
private Timer mTimer = null;
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
// cancel if already existed
if(mTimer != null) {
mTimer.cancel();
} else {
// recreate new
mTimer = new Timer();
}
// schedule task
mTimer.scheduleAtFixedRate(new TimeDisplayTimerTask(), 0, NOTIFY_INTERVAL);
}
class TimeDisplayTimerTask extends TimerTask {
@Override
public void run() {
// run on another thread
mHandler.post(new Runnable() {
@Override
public void run() {
// display toast
Toast.makeText(getApplicationContext(), "hello",
Toast.LENGTH_SHORT).show();
}
});
}
看看这个:
它解释了如何获取设备上的当前位置。您使用emulator吗?您需要一个真实的设备来获取当前lat,lng。是的,正如@sunit所说,您需要一个真实的设备,在emulator上输入的应该是您的坐标。所以最好试一下设备!我确实使用了一个真正的设备,但当我使用它时,我甚至无法通过模拟器控件发送横向、纵向坐标。所以当我运行我的服务时。基本上什么也没发生:/@sunit如果你的设备上有真正的lat,long,那么需要做什么呢。而且,您不能通过仿真器控件向真实设备发送lat和long坐标。