相关疑难解决方法(0)

199
推荐指数
10
解决办法
23万
查看次数

在某些设备上没有调用onLocationChanged

这个问题曾被多次提出,但我找不到始终有效的解决方案.

我正在使用Fused位置提供程序开发应用程序.在该onConnected()方法中,我请求位置更新,并且一旦生成并onLocationChanged()调用位置修复,将启动应用程序逻辑.(请参阅下面的代码).

onLocationChanged()在某些设备上永远不会调用问题方法.我使用三星Tab 2和三星Galaxy Grand进行测试.此代码在Tab 2上完美运行,但不适用于Grand.通过不起作用,我的意思是locationClient连接但onLocationChanged()永远不会被调用.

之前,我使用位置管理器获取位置,在该实现中,发生了同样的问题.所以,我尝试实现融合的位置提供程序,但我仍然遇到同样的问题.

任何人都可以帮我解决这个问题吗?这里有什么我想念的吗?

public class MainActivity extends Activity implements GooglePlayServicesClient.ConnectionCallbacks, OnConnectionFailedListener, LocationListener {

LocationClient locationclient;
LocationRequest lr;
Location loc1;
static String address;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);     

    locationclient = new LocationClient(this,this,this);
    locationclient.connect();        

}

@Override
public void onConnected(Bundle arg0) {
    // TODO Auto-generated method stub

    lr=LocationRequest.create();
    lr.setInterval(100);
    locationclient.requestLocationUpdates(lr, this);
    Log.d("LocationClient","On Connected");
}

@Override
public void onDisconnected() {
    // TODO Auto-generated method stub …
Run Code Online (Sandbox Code Playgroud)

android location-client

18
推荐指数
2
解决办法
7399
查看次数

LocationClient requestUpdates onLocationChanged从未调用过

我有这个代码用于定位地图应用程序.我在Galaxy S2设备上测试它并且工作正常,但是当我在nexus 4设备中测试它时,onLocationChanged回调永远不会被调用.我能做错什么?

这是我的活动代码:

    public class BaseMapActivity extends FragmentActivity implements Injectable,
        GooglePlayServicesClient.ConnectionCallbacks,
        GooglePlayServicesClient.OnConnectionFailedListener, LocationListener {

    private final static int CONNECTION_FAILURE_RESOLUTION_REQUEST = 9000;

    private MapEntity component;
    private boolean yetStarted = false;

    private LocationClient mLocationClient;
    private LocationRequest mLocationRequest;
    private Location location;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.map_activity);
        mLocationClient = new LocationClient(this, this, this);
        mLocationRequest = LocationRequest.create();

        mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); // TODO
        mLocationRequest.setInterval(5000); // TODO
        mLocationRequest.setFastestInterval(5000); // TODO

        replaceFragment(R.id.map_container, mapFragment);

        // Agrega el fragment de extras
        Fragment extrasFragment = component.getExtrasFragment();
        replaceFragment(R.id.map_extras, extrasFragment); …
Run Code Online (Sandbox Code Playgroud)

java android location-client

6
推荐指数
1
解决办法
1055
查看次数

播放位置服务getLastLocation返回null

我正在尝试收听位置更改,但有时onLocationChanged回调永远不会被调用并getLastLocation返回null,而Google地图始终完美运行.

注意

如果我重新启动设备,位置服务将仅工作约2天; 之后,Google地图仍在运行时,我的应用和SDK示例都无效.

这是我的服务代码:

public class VisitService extends Service implements
        GooglePlayServicesClient.ConnectionCallbacks,
        GooglePlayServicesClient.OnConnectionFailedListener, 
        LocationListener {

    private final IBinder mBinder = new VisitBinder();


    // A request to connect to Location Services
    private LocationRequest mLocationRequest;

    // Stores the current instantiation of the location client in this object
    private LocationClient mLocationClient;


    private boolean mLocationServiceConnected = false;

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        initLocation();
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public IBinder …
Run Code Online (Sandbox Code Playgroud)

java android google-play-services

3
推荐指数
1
解决办法
7905
查看次数