i created an Android activity to show Google Maps. I would center the map to the current user position but i cannot figure out how to do it.
Here is my current code:
Location location = getMyLocation();
LatLng userPos = new LatLng(location.getLatitude(), location.getLongitude());
map.animateCamera(CameraUpdateFactory.newLatLngZoom(userPos, zoomLevel));
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(userPos)
.zoom(17)
.bearing(90)
.tilt(40)
.build();
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
The source of this code is this answer (where i copied getMyLocation() from) and this solution, but they don't work. In both cases it doesn't work at all: the center is not set and weirdly neither the zoom level is set.
If i use just this code (without current user position):
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(42.564241, 12.22759), zoomLevel));
it works with no problem, even the zoom level is set.
What could be the problem?