use of com.google.android.gms.location.LocationResult in project TrekAdvisor by peterLaurence.
the class LocationService method onCreate.
@Override
public void onCreate() {
EventBus.getDefault().register(this);
/* Start up the thread running the service. Note that we create a separate thread because
* the service normally runs in the process's main thread, which we don't want to block.
* We also make it background priority so CPU-intensive work will not disrupt our UI.
*/
HandlerThread thread = new HandlerThread("LocationServiceThread", Thread.MIN_PRIORITY);
thread.start();
/* Get the HandlerThread's Looper and use it for our Handler */
mServiceLooper = thread.getLooper();
mServiceHandler = new Handler(mServiceLooper);
mServiceHandler.handleMessage(new Message());
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this.getApplicationContext());
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(1000);
mLocationRequest.setFastestInterval(1000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
/* Create the Gpx instance */
mTrackPoints = new ArrayList<>();
mLocationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
for (Location location : locationResult.getLocations()) {
mServiceHandler.post(() -> {
TrackPoint.Builder pointBuilder = new TrackPoint.Builder();
pointBuilder.setLatitude(location.getLatitude());
pointBuilder.setLongitude(location.getLongitude());
pointBuilder.setElevation(location.getAltitude());
TrackPoint trackPoint = pointBuilder.build();
mTrackPoints.add(trackPoint);
});
}
}
};
startLocationUpdates();
}
use of com.google.android.gms.location.LocationResult in project PhoneProfilesPlus by henrichg.
the class LocationGeofenceEditorActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
// must by called before super.onCreate() for PreferenceActivity
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
GlobalGUIRoutines.setTheme(this, false, true, false);
else
GlobalGUIRoutines.setTheme(this, false, false, false);
GlobalGUIRoutines.setLanguage(getBaseContext());
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_location_geofence_editor);
mResultReceiver = new AddressResultReceiver(new Handler(getMainLooper()));
// Create a GoogleApiClient instance
mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API).addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();
mLocationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
PPApplication.logE("LocationGeofenceEditorActivity.LocationCallback", "xxx");
if (locationResult == null) {
return;
}
for (Location location : locationResult.getLocations()) {
mLastLocation = location;
PPApplication.logE("LocationGeofenceEditorActivity.LocationCallback", "location=" + location);
if (mLocation == null) {
mLocation = new Location(mLastLocation);
refreshActivity(true);
} else
updateEditedMarker(false);
}
}
};
createLocationRequest();
mResolvingError = savedInstanceState != null && savedInstanceState.getBoolean(STATE_RESOLVING_ERROR, false);
Intent intent = getIntent();
geofenceId = intent.getLongExtra(LocationGeofencePreference.EXTRA_GEOFENCE_ID, 0);
if (geofenceId > 0) {
geofence = DatabaseHandler.getInstance(getApplicationContext()).getGeofence(geofenceId);
mLocation = new Location("LOC");
mLocation.setLatitude(geofence._latitude);
mLocation.setLongitude(geofence._longitude);
}
if (geofence == null) {
geofenceId = 0;
geofence = new Geofence();
geofence._name = getString(R.string.event_preferences_location_new_location_name) + "_" + String.valueOf(DatabaseHandler.getInstance(getApplicationContext()).getGeofenceCount() + 1);
geofence._radius = 100;
}
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.location_editor_map);
mapFragment.getMapAsync(this);
radiusLabel = findViewById(R.id.location_pref_dlg_radius_seekbar_label);
SeekBar radiusSeekBar = findViewById(R.id.location_pref_dlg_radius_seekbar);
radiusSeekBar.setProgress(Math.round(geofence._radius / (float) 20.0) - 1);
radiusSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
geofence._radius = (progress + 1) * 20;
updateEditedMarker(false);
// Log.d("LocationGeofenceEditorActivity.onProgressChanged", "radius="+geofence._radius);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
geofenceNameEditText = findViewById(R.id.location_editor_geofence_name);
geofenceNameEditText.setText(geofence._name);
addressText = findViewById(R.id.location_editor_address_text);
okButton = findViewById(R.id.location_editor_ok);
okButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name = geofenceNameEditText.getText().toString();
if ((!name.isEmpty()) && (mLocation != null)) {
geofence._name = name;
geofence._latitude = mLocation.getLatitude();
geofence._longitude = mLocation.getLongitude();
if (geofenceId > 0) {
DatabaseHandler.getInstance(getApplicationContext()).updateGeofence(geofence);
} else {
DatabaseHandler.getInstance(getApplicationContext()).addGeofence(geofence);
/*synchronized (PPApplication.geofenceScannerMutex) {
// start location updates
if ((PhoneProfilesService.instance != null) && PhoneProfilesService.isGeofenceScannerStarted())
PhoneProfilesService.getGeofencesScanner().connectForResolve();
}*/
}
DatabaseHandler.getInstance(getApplicationContext()).checkGeofence(String.valueOf(geofence._id), 1);
Intent returnIntent = new Intent();
returnIntent.putExtra(LocationGeofencePreference.EXTRA_GEOFENCE_ID, geofence._id);
setResult(Activity.RESULT_OK, returnIntent);
finish();
}
}
});
Button cancelButton = findViewById(R.id.location_editor_cancel);
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent returnIntent = new Intent();
setResult(Activity.RESULT_CANCELED, returnIntent);
finish();
}
});
AppCompatImageButton myLocationButton = findViewById(R.id.location_editor_my_location);
myLocationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mLastLocation != null)
mLocation = new Location(mLastLocation);
refreshActivity(true);
}
});
addressButton = findViewById(R.id.location_editor_address_btn);
addressButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getGeofenceAddress();
}
});
}
use of com.google.android.gms.location.LocationResult in project HikingApp by wickhama.
the class Tracking method onCreate.
@Override
public void onCreate() {
// Asks for permission
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
stopSelf();
}
trail = new ArrayList();
flocatClient = LocationServices.getFusedLocationProviderClient(getApplicationContext());
locationRequest.setInterval(1000);
locationRequest.setFastestInterval(5000);
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationCallback = new LocationCallback() {
private Intent intent = new Intent();
@Override
public void onLocationResult(LocationResult locationResult) {
if (locationResult == null) {
return;
}
intent.setAction(LOCATION_FOUND);
for (Location location : locationResult.getLocations()) {
trail.add(new LatLng(location.getLatitude(), location.getLongitude()));
intent.putExtra("location", trail);
sendBroadcast(intent);
}
}
};
}
use of com.google.android.gms.location.LocationResult in project android-play-location by googlesamples.
the class LocationUpdatesIntentService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
if (intent != null) {
final String action = intent.getAction();
if (ACTION_PROCESS_UPDATES.equals(action)) {
LocationResult result = LocationResult.extractResult(intent);
if (result != null) {
List<Location> locations = result.getLocations();
Utils.setLocationUpdatesResult(this, locations);
Utils.sendNotification(this, Utils.getLocationResultTitle(this, locations));
Log.i(TAG, Utils.getLocationUpdatesResult(this));
}
}
}
}
use of com.google.android.gms.location.LocationResult in project GogoNew by kuldeep725.
the class MapsActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
progressDialog = new ProgressDialog(this);
floatingButton = (FloatingActionButton) findViewById(R.id.pick_me);
flag2 = 1;
// broadCast = new NetworkChangeReceiver(new MapsActivity());
Intent i = new Intent(this, NetworkChangeReceiver.class);
sendBroadcast(i);
// registerReceiver(broadCast, new IntentFilter("INTERNET_LOST"));
// FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
// fab.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
// .setAction("Action", null).show();
// }
// });
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
distance = (TextView) findViewById(R.id.distance);
duration = (TextView) findViewById(R.id.time);
mDatabase = FirebaseDatabase.getInstance().getReference();
mRequestingLocationUpdates = false;
if (checkPermissions()) {
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
Log.d(TAG, "onCreate ...............................");
createLocationRequest();
// show error dialog if GoolglePlayServices not available
// if (!isGooglePlayServicesAvailable()) {
// finish();
// }
mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API).addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
// mFusedLocationClient is actually responsible for mCurrentLocation
mFusedLocationClient.getLastLocation().addOnSuccessListener(this, new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
// Got last known location. In some rare situations this can be null.
if (location != null) {
mCurrentLocation = location;
Log.d(TAG, "@mFusedLocationClient -> mCurrentLocation = " + mCurrentLocation.toString());
onMapReady(mMap);
// if (checkBusSelection != 0 && flag2 != 0) {
// makeMarkerOnTheLocation();
// showMarkers();
// showDistanceInBetween();
// flag2 = 0;
// }
}
}
});
// brilliant function keeps checking the change in the location and update it in the interval set by us in createLocationRequest
mLocationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
for (Location location : locationResult.getLocations()) {
mCurrentLocation = location;
// Log.d(TAG, "mLocationCallback mCurrentLocation= "+ mCurrentLocation.toString());
showInternetStatus();
}
// showMyLocationMarker();
}
};
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setupWindowAnimations();
}
}
Aggregations