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);
}
Aggregations