小编Roh*_*hit的帖子

在某些设备上没有调用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
查看次数

标签 统计

android ×1

location-client ×1