Android Studio, Google Maps, what to write in the code so that the current position is always displayed in the center of the screen?

And then it turns out the map is fixed, and the point with the online position has moved beyond the edge of the visible area.

    1 answer 1

    First of all, when you receive a new Location extract the longitude and latitude from it and collect the LatLng object. Then create an object

    CameraUpdate cu = CameraUpdateFactory.newLatLng(latlng);

    And apply it to the mGoogleMap.moveCamera(cu) map without animation or .animateCamera(cu) with animation if you want. To do all these operations with each update location. Then your point will always be in the center of the screen.

    Read more about this in the documentation.

    • Thank!!! I used this method mGoogleMap.moveCamera (cu), took an example from google, it shows the position exactly, the standard label with the current position is shifted when moving, but the map itself "stands" in place and the label goes off the screen. Maybe you need to put mGoogleMap.moveCamera (cu) in another place? - Rinat
    • You have a callback where the new location falls. go there update camera - Sviat Volkov