0

マップに基づいてアプリケーションをテストするためにモックロケーション(FusedLocationApiを使用)を設定していますが、動作しないようです。setMockModeが機能しません - FusedLocationApi

LocationServices.FusedLocationApi.setMockMode(mGoogleApiClient, true); 


Location location = new Location("fused"); 
      // Time is needed to create a valid Location 
      long currentTime = System.currentTimeMillis(); 
      long elapsedTimeNanos = 0; 
      if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { 
       elapsedTimeNanos = SystemClock.elapsedRealtimeNanos(); 
       location.setElapsedRealtimeNanos(elapsedTimeNanos); 
      } 
      location.setTime(currentTime); 
      // new york 40.7128° N, 74.0059° W 
      location.setLatitude(40.7128); 
      location.setLongitude(74.0059); 
      PendingResult<Status> s = LocationServices.FusedLocationApi.setMockLocation(mGoogleApiClient, location); 
      s.setResultCallback(new ResolvingResultCallbacks<Status>(MainActivity.this, 100) { 
       @Override 
       public void onSuccess(@NonNull Status status) { 
        if(status.isSuccess()){ 
         log("mock success"); 

         if (mIsFromContinuousUpdates) { 
          startContinuousUpdates(); 
          return; 
         } 
         getLastKnowLocation(); 
        } 
       } 

       @Override 
       public void onUnresolvableFailure(@NonNull Status status) { 

       } 
      }); 

PendingResultリターンの成功が、私はgetLastKnownLocationを呼び出すとき、それは私が継続的な更新を要求するときnullonLocationChangedがトリガされていませんが返されます。

ここに何か不足していますか?

+0

任意の答えを? ..... – mallaudin

答えて

0

位置更新を開始するとき、それは意図パラメータ

public class LocationUpdateActivity extends IntentService implements LocationListener { 
private static final String TAG = LocationUpdateActivity .class.getSimpleName(); 
private Location mCurrentLocation; 

public LocationUpdateActivity(String name) { 
    super(name); 
} 
public LocationUpdateActivity() { 
    super("LocationUpdateActivity"); 
} 

@Override 
protected void onHandleIntent(@Nullable Intent intent) { 
    Log.i(TAG, "onHandleIntent"); 
    if (LocationResult.hasResult(intent)) { 
     LocationResult locationResult = LocationResult.extractResult(intent); 
     mCurrentLocation = locationResult.getLastLocation(); 
     if (mCurrentLocation != null) { 
      Log.d(TAG, "accuracy: " + mCurrentLocation.getAccuracy() + " lat: " + mCurrentLocation.getLatitude() + " lon: " + mCurrentLocation.getLongitude()); 
     } 
    } 
} 

、設定の更新から場所を抽出OnHandleIntentをimplemnts pendingIntent、受け取るべきである:

Intent locationIntent = new Intent(mContext, LocationUpdateActivity.class); 
PendingIntent locationPendingIntent = PendingIntent.getService(
          mContext, 
          0, 
          locationIntent, 
          PendingIntent.FLAG_UPDATE_CURRENT 
        ); 

FusedLocationApi.requestLocationUpdates(
          mGoogleApiClient, mLocationRequest, locationPendingIntent); 
+0

動作しません。私はこのメソッドを 'Fused Provider'で見つけることさえできません。 – mallaudin

関連する問題