LocationClient - Mock Locations

I am using LocationClient, which works well. Now I'm trying to create a location layout (setMockMode (true) + setMockLocation (mockLoc), but the onLocationChanged from my LocationListener is not called. What could be the problem?

I followed this up: http://developer.android.com/training/location/location-testing.html

Steps:

  • connecting
  • requestLocationUpdates
  • setMockMode true
  • setMockLocation (provider = "flp")
+4
source share
1 answer

So, you need to update your locations with setTime()and setElapsedRealtimeNanos().

:

@SuppressLint("NewApi")
public Location createLocation(double lat, double lng, float accuracy) {
    // Create a new Location
    Location newLocation = new Location(PROVIDER);
    newLocation.setLatitude(lat);
    newLocation.setLongitude(lng);
    newLocation.setAccuracy(accuracy);
    newLocation.setTime(System.currentTimeMillis());

    int sdk = android.os.Build.VERSION.SDK_INT;
    if(sdk >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
        newLocation.setElapsedRealtimeNanos(
             SystemClock.elapsedRealtimeNanos());
    }
    return newLocation;
}

Nexus 5.

+7

Source: https://habr.com/ru/post/1542302/


All Articles