onLocationChanged未被调用(使用PendingIntent)

时间:2014-05-13 18:07:06

标签: android location

我看过其他与此相关的帖子,但我无法从中找到答案。我正在实现一个不断更新和存储您当前位置的Android应用程序。我的调试日志显示它执行requestLocationUpdates代码,但它从不执行onLocationChanged代码。

这是我实现位置的地方:

mLocationClient = new LocationClient(this, this, this);
        mLocationRequest = LocationRequest.create();
        mLocationRequest.setFastestInterval(2000);
        mLocationRequest.setInterval(5000);
        mLocationRequest.setPriority(102);
        mLocationClient.connect();

我有一个记录是否存储位置的按钮,它位于该按钮的功能中:

if ((mLocationClient != null) && (mLocationClientConnected) && (mLocationRequest != null)) {
                        PendingIntent pendingIntent = PendingIntent.getBroadcast(getActivity(), 0, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT);
                        mLocationClient.requestLocationUpdates(mLocationRequest, pendingIntent);
                        Log.i("requesting", "updating");
                    }

这是我的onLocationChanged代码:

@Override
public void onLocationChanged(Location location) {
    String display = "("+location.getLatitude()+","+location.getLongitude()+")";
    this.lastLocation = display;
    updateUI();
    Log.i("location", "in on location changed");
    if ((mLocationClient != null) && (mLocationClientConnected) && (mLocationRequest != null)) {
        Point current = new Point(location.getTime(), location.getLatitude(), location.getLongitude());
        stroke_manager.addPoint(stroke_name, current);
        Log.i("adding", "points added");
    }
}

0 个答案:

没有答案