Skip to content

Instantly share code, notes, and snippets.

@MrCrambo
Last active July 11, 2020 07:52
Show Gist options
  • Save MrCrambo/6dee10a649ca3b959c37216d916640cf to your computer and use it in GitHub Desktop.
Save MrCrambo/6dee10a649ca3b959c37216d916640cf to your computer and use it in GitHub Desktop.
private void setMock(String provider, double latitude, double longitude) {
mLocationManager.addTestProvider (provider, false, false, false, false, false, true, true, 0, 5);
Location newLocation = new Location(provider);
newLocation.setLatitude(latitude);
newLocation.setLongitude(longitude);
newLocation.setAltitude(3F);
newLocation.setTime(System.currentTimeMillis());
newLocation.setSpeed(0.01F);
newLocation.setBearing(1F);
newLocation.setAccuracy(3F);
newLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
{
newLocation.setBearingAccuracyDegrees(0.1F);
newLocation.setVerticalAccuracyMeters(0.1F);
newLocation.setSpeedAccuracyMetersPerSecond(0.01F);
}
mLocationManager.setTestProviderEnabled(provider, true);
mLocationManager.setTestProviderLocation(provider, newLocation);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment