获取更改位置的 GPS 状态 [英] Get GPS Status on location changed

查看:27
本文介绍了获取更改位置的 GPS 状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 GPS 服务来获取纬度&我的应用程序中的经度.当信号可用时,我能够获得纬度和经度.一旦我得到修复,如果我必须去一个 GPS 无法获得定位的地方,它仍然会显示最后一个位置.我想获取当前位置而不是其他位置.我曾尝试使用 onLocationChanged() 和 onGpsStatusChanged() 来获取 GPS 状态,但它没有给我结果.

I am using GPS services to derive latitude & longitude in my App. I am able to get the latitude and longitude when the signal is avialable. Once i get a fix, if i have to go to a place where the GPS is not able to get a location fix, it still shows the last location. I want to get the current location and not otherwise. I have tried using onLocationChanged() and onGpsStatusChanged() both to get the GPS status but it isnt giving me the result.

@Override
public void onGpsStatusChanged(int arg0) {
    // TODO Auto-generated method stub
    if (event == GpsStatus.GPS_EVENT_STARTED) {
        Log.d("zmenaGPS" , "GPS event started ");
        GpsStatus gs = mlocManager.getGpsStatus(null);
        Toast.makeText(getApplicationContext(),String.valueOf(gs),Toast.LENGTH_LONG).show();

    } else if (event == GpsStatus.GPS_EVENT_STOPPED) {
        Log.d("zmenaGPS" , "GPS event stopped ");
        GpsStatus gs = mlocManager.getGpsStatus(null);
        Log.d("zmenaGPSgps status" , String.valueOf(gs));
        Toast.makeText(getApplicationContext(),String.valueOf(gs),Toast.LENGTH_LONG).show();

    } else if (event == GpsStatus.GPS_EVENT_FIRST_FIX) {
        Log.d("zmenaGPS" , "GPS fixace ");
        Toast.makeText(getApplicationContext(),"First Fix",Toast.LENGTH_LONG).show();
    } else if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) {
        Log.d("zmenaGPS" , "GPS EVET NECO ");
    } 

}

推荐答案

听起来像是要获取当前位置,而您想知道当前位置何时未知,所以不要尝试使用旧位置.这种情况下,你可以尝试获取当前位置,然后测试它是否旧.

It sounds like you want to get the current location, and you want to know when a current location is unknown, so you do not try to use an old location. In that case, you can try to get the current location, and then test if it is old or not.

long fresh=60000; // 1 minute in milliseconds
if(System.currentTimeMillis()-location.getTime()>fresh)
    // Do something useful with location

这篇关于获取更改位置的 GPS 状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆