GPS定位没有发生的第一次。在通知栏无状态 [英] GPS fix Is not happening for the first time. No status in notification bar

查看:347
本文介绍了GPS定位没有发生的第一次。在通知栏无状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建一个地点报警基于应用程序。一切都是仿真器工作正常。但在实际的设​​备会出现以下错误。

情景:

开机状态的GPS。
打开我的应用程序在手机上。
在状态栏上没有GPS的象征。
应用获得力量关闭。

要解决这种情况下,我做以下的事情

像打开地图,GPS必备的应用程序。
我的GPS值的搞定了。
开场之后我的应用程序。
应用程序正常工作。

提供了必要的codeS如下:

在我的onCreate方法

  fixlocation = orgManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
@覆盖
保护无效onResume(){
    super.onResume();
    orgManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,1000,这一点);
    orgManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,1000,这一点);
    mo.enableCompass();
    mo.enableMyLocation();
}/ **停止更新活动时暂停* /
@覆盖
保护无效的onPause(){
    super.onPause();
    orgManager.removeUpdates(本);
    mo.disableCompass();
    mo.disableMyLocation();
}@覆盖
    公共无效onLocationChanged(地点){
        // TODO自动生成方法存根        //orgManager.removeUpdates(this);        如果(位置!= NULL){
            currLatitude = location.getLatitude();
            currLongtitude = location.getLongitude();
}}

什么我现在需要做的?


解决方案

 的LocationManager LM =(的LocationManager)getSystemService(Context.LOCATION_SERVICE);
地点= lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);currLat = location.getLatitude();
currentLang = location.getLongitude();

试试这个来获得当前位置。

onLocationChanged只会打电话的时候,你的设备改变位置,但

第一次应用程序启动时,您可以使用此code。

Created a Location alarm based app. Everything is working fine on emulator. But the following error occurs in real device.

Scenario:

Turned on GPS. Opened my app in phone. No GPS symbol in status bar. App getting force closed.

To fix this scenario, I am doing the following thing

Open any application like Maps, GPS Essentials. My GPS values is getting fixed. Opening my application after that. App working fine.

Providing the necessary codes below:

in my Oncreate method

fixlocation = orgManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);


@Override
protected void onResume() {
    super.onResume();
    orgManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1000, this);
    orgManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 1000, this);
    mo.enableCompass();
    mo.enableMyLocation();
}

/** Stop the updates when Activity is paused */
@Override
protected void onPause() {
    super.onPause();
    orgManager.removeUpdates(this);
    mo.disableCompass();
    mo.disableMyLocation();
}



@Override
    public void onLocationChanged(Location location) {
        // TODO Auto-generated method stub

        //orgManager.removeUpdates(this);

        if (location != null) {
            currLatitude = location.getLatitude();
            currLongtitude = location.getLongitude();
}}

What do I need to do now?

解决方案

LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);

currLat = location.getLatitude();
currentLang = location.getLongitude();

Try this to get current location.

onLocationChanged will call only when location of your device changes but

first time when your application starts you can use this code.

这篇关于GPS定位没有发生的第一次。在通知栏无状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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