Example usage for android.location LocationManager setTestProviderLocation

List of usage examples for android.location LocationManager setTestProviderLocation

Introduction

In this page you can find the example usage for android.location LocationManager setTestProviderLocation.

Prototype

public void setTestProviderLocation(String provider, Location loc) 

Source Link

Document

Sets a mock location for the given provider.

Usage

From source file:org.cowboycoders.cyclisimo.turbo.TurboService.java

private synchronized void updateLocation(LatLongAlt pos) {
    LocationManager locationManager = (LocationManager) getApplicationContext()
            .getSystemService(Context.LOCATION_SERVICE);
    if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        try {//from  w w w . j  ava 2s. c om
            float locSpeed = (float) (lastRecordedSpeed / UnitConversions.MS_TO_KMH);
            final long timestamp = System.currentTimeMillis();
            Log.v(TAG, "location timestamp: " + timestamp);
            Location loc = new Location(MOCK_LOCATION_PROVIDER);
            Log.d(TAG, "alt: " + pos.getAltitude());
            Log.d(TAG, "lat: " + pos.getLatitude());
            Log.d(TAG, "long: " + pos.getLongitude());
            loc.setLatitude(pos.getLatitude());
            loc.setLongitude(pos.getLongitude());
            loc.setAltitude(pos.getAltitude());
            loc.setTime(timestamp);
            loc.setSpeed(locSpeed);
            loc.setAccuracy(GPS_ACCURACY);
            locationManager.setTestProviderLocation(MOCK_LOCATION_PROVIDER, loc);
            Log.e(TAG, "updated location");
        } catch (SecurityException e) {
            handleException(e, "Error updating location", true, NOTIFCATION_ID_STARTUP);
        }

        return;
    }
    Log.e(TAG, "no gps provider");

}