0

Android のジオフェンシングに問題があります。https://developer.android.com/training/location/geofencing.htmlの指示に従います。 ジオフェンスのリストを作成し、LocationClient に接続すると動作し、接続が返され、最後の位置を取得できます。しかし、実行すると:

mLocationClient.addGeofences(InfoApp.mGeofenceList, mTransitionPendingIntent, this);

onAddGeofencesResult に応答がありません。logcat にメッセージが表示されません。

次のコードでジオフェンスを作成します。

mUIGeofence1 = new SimpleGeofence(
infoEstablecimiento.getString("_id"),
infoEstablecimiento.getDouble("latitud"),
infoEstablecimiento.getDouble("longitud"),
(float) infoEstablecimiento.getDouble("radio"),
Geofence.NEVER_EXPIRE,
// This geofence records only entry transitions with a delay
Geofence.GEOFENCE_TRANSITION_DWELL, loiteringDelay);

まず、REQUEST_TYPE.ADD を使用してこの関数を呼び出します。

public static void conexionGeofence(
        REQUEST_TYPE mRequestType,
        Context contexto,
        SlidingFragmentActivity actividad,
        GooglePlayServicesClient.ConnectionCallbacks connectionAct,
        GooglePlayServicesClient.OnConnectionFailedListener connectionListener) {
    // Start a request to add geofences
    /*
     * Test for Google Play services after setting the request type. If
     * Google Play services isn't present, the proper request can be
     * restarted.
     */
    if (!servicesConnected(actividad)) {
        return;
    }
    /*
     * Create a new location client object. Since the current activity class
     * implements ConnectionCallbacks and OnConnectionFailedListener, pass
     * the current activity object as the listener for both parameters
     */
    InfoApp.mLocationClient = new LocationClient(contexto, connectionAct,
            connectionListener);

    // If a request is not already underway
    if (!InfoApp.mInProgress) {
        InfoApp.mRequestType = mRequestType;

        // Indicate that a request is underway
        InfoApp.mInProgress = true;
        // Request a connection from the client to Location Services
        InfoApp.mLocationClient.connect();
    } else {
        /*
         * A request is already underway. You can handle this situation by
         * disconnecting the client, re-setting the flag, and then re-trying
         * the request.
         */
    }
}

onConnected で応答を受け取りましたが、addGeofences を呼び出しても応答がありません。

@Override
public void onConnected(Bundle connectionHint) {
    /*
     * Choose what to do based on the request type set in removeGeofences
     */
    switch (InfoApp.mRequestType) {
    case ADD:
        // Get the PendingIntent for the request
        InfoApp.mTransitionPendingIntent = GeofenceUtils
                .getTransitionPendingIntent();

        Location loc = InfoApp.mLocationClient.getLastLocation();

        // Send a request to add the current geofences
        InfoApp.mLocationClient.addGeofences(InfoApp.mGeofenceList,
                InfoApp.mTransitionPendingIntent, this);
        break;

    case REMOVE_LIST:
        InfoApp.mLocationClient.removeGeofences(InfoApp.mGeofencesToRemove,
                this);
        break;

    default:
        break;
    }

}

どうもありがとうございました!

4

2 に答える 2

0

がつながるaddGeofences()まで電話を待っていましたか?LocationClient

于 2014-03-26T19:07:27.850 に答える
-1

次の ADD ケースを検討してください。

    // Get the PendingIntent for the request
    InfoApp.mTransitionPendingIntent = GeofenceUtils
            .getTransitionPendingIntent();

    Location loc = InfoApp.mLocationClient.getLastLocation();

    // Send a request to add the current geofences
    InfoApp.mLocationClient.addGeofences(InfoApp.mGeofenceList,
            InfoApp.mTransitionPendingIntent, this);
    break;

が接続さaddGeofences()れるまで電話を待っていましたか?LocationClient

于 2014-07-01T10:50:15.510 に答える