I'm building an app, which has to keep the user in the center of the map all the time.
I have set up the following:
locationManager = (LocationManager) saveContext
.getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = new MapLocationListener();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000,
10, locationListener);
if (myLocation != null) {
setLocation(myLocation);
}
private void setLocation(Location location) {
workoutMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(
location.getLatitude(), location.getLongitude()), 18.0f));
}
This works, as long I have a lastKnownLocation in my phone's history. The map will center correctly.
I wish that every time I'm getting a new location update, setLocation() will be executed again, with the new location info.
I've tried creating a thread which just does get the lastKnownLocation and then setLocation(); But this isn't working out.