There are two functions I would call, one for centering the marker and an other one to zoom on the map until your current location is still visible.
My solution for zooming to a point with a 15 zoom level:
myMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLngToCenter, 1));
zooming until all markers are still visible (change code to fit the marker and your position instead):
public void fitZoomAndPositionToMapByMarkers() {
int minLat = Integer.MAX_VALUE;
int maxLat = Integer.MIN_VALUE;
int minLon = Integer.MAX_VALUE;
int maxLon = Integer.MIN_VALUE;
List<MyMapMarker> markersShownOnMap = getMarkersToShow();
for (MyMapMarker item : markersShownOnMap) {
int lat = (int) (item.getLatitude() * 1E6);
int lon = (int) (item.getLongitude() * 1E6);
maxLat = Math.max(lat, maxLat);
minLat = Math.min(lat, minLat);
maxLon = Math.max(lon, maxLon);
minLon = Math.min(lon, minLon);
}
double latitudeToGo = (maxLat + minLat) / 1E6 / 2;
double longitudeToGo = (maxLon + minLon) / 1E6 / 2;
LatLng toCenter = new LatLng(latitudeToGo, longitudeToGo);
centerCameraToProperPosition(toCenter);
LatLng southWestLatLon = new LatLng(minLat / 1E6, minLon / 1E6);
LatLng northEastLatLon = new LatLng(maxLat / 1E6, maxLon / 1E6);
zoomInUntilAllMarkersAreStillVisible(southWestLatLon, northEastLatLon);
}
Hope this helps!
private void zoomInUntilAllMarkersAreStillVisible(final LatLng southWestLatLon, final LatLng northEastLatLon) {
myMap.setOnCameraChangeListener(new OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition arg0) {
myMap.moveCamera(CameraUpdateFactory.newLatLngBounds(new LatLngBounds(southWestLatLon, northEastLatLon), 50));
myMap.setOnCameraChangeListener(null);
}
});
}