How is it possible to bring the map immediately across the locality, namely, if, like an example, the markers are in the same city, then immediately open the approximate map of this city. enter image description here

Markers are added as follows:

public class MapActivity extends FragmentActivity implements OnMapReadyCallback { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_map); createMapView(); } private void createMapView() { MapFragment mapFragment = (MapFragment) getFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); } @Override public void onMapReady(GoogleMap map) { map.getUiSettings().setZoomControlsEnabled(true); LatLngBounds.Builder builder = new LatLngBounds.Builder(); Marker marker = map.addMarker(new MarkerOptions() .position(new LatLng(0, 0)) .title("Marker")); builder.include(marker.getPosition()); LatLngBounds bounds = builder.build(); int padding = 50; CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding); map.moveCamera(cu); } 

PS probably not the best solution.

    1 answer 1

    You need to use LatLngBounds

     LatLngBounds.Builder builder = new LatLngBounds.Builder(); Marker marker = map.addMarker(new MarkerOptions() .position(new LatLng(0, 0)) .title("Marker")); builder.include(marker.getPosition()); //засунуть все маркеры LatLngBounds bounds = builder.build(); int padding = 50; // offset from edges of the map in pixels CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding); map.moveCamera(cu); 
    • Thanks for the answer, but could you please explain a little bit exactly how I can "shove all the markers" into marker.getPosition if I now add the markers as shown in the question (updated the question). - Morozov
    • @Morozov, updated the answer - katso
    • The marker "floated" into the sea) now even with a zoom I cannot zoom in on the territory or move around the map somewhere. - Morozov
    • @Morozov, the campaign you did, that something is wrong - katso
    • one
      @Morozov, that's right, the coordinates 0, 0 are in the Atlantic Ocean. - katso