Search in sources :

Example 1 with LocationResult

use of io.joynr.examples.android_location_provider.MyLocation.LocationResult in project joynr by bmwcarit.

the class AndroidLocationProvider method initLocationProviderAndListener.

private void initLocationProviderAndListener() {
    // LocationResult.gotLocation will be called when android notifies about a new location
    locationResult = new LocationResult() {

        @Override
        public void gotLocation(Location androidLocation) {
            GpsLocation joynrLocation = new GpsLocation();
            if (androidLocation != null) {
                joynrLocation.setLatitude(androidLocation.getLatitude());
                joynrLocation.setLongitude(androidLocation.getLongitude());
                joynrLocation.setAltitude(androidLocation.getAltitude());
                joynrLocation.setGpsFix(GpsFixEnum.MODE3D);
            } else {
                joynrLocation.setGpsFix(GpsFixEnum.MODENOFIX);
            }
            // applies the location to the location provider and notifies onChange subscriptions
            locationChanged(joynrLocation);
        }
    };
    // Use myLocation to asynchronously obtain a location
    myLocation = new MyLocation();
    myLocation.getLocation(applicationContext, locationResult);
    // Attempt to update the location every 20 seconds
    scheduler.scheduleWithFixedDelay(new Runnable() {

        @Override
        public void run() {
            myLocation.getLocation(applicationContext, locationResult);
        }
    }, 0, 20000, TimeUnit.MILLISECONDS);
}
Also used : GpsLocation(joynr.types.Localisation.GpsLocation) LocationResult(io.joynr.examples.android_location_provider.MyLocation.LocationResult) GpsLocation(joynr.types.Localisation.GpsLocation) Location(android.location.Location)

Aggregations

Location (android.location.Location)1 LocationResult (io.joynr.examples.android_location_provider.MyLocation.LocationResult)1 GpsLocation (joynr.types.Localisation.GpsLocation)1