你需要使用newLatLngBounds()
Returns a CameraUpdate that transforms the camera such that the specified latitude/longitude bounds are centered on screen at the greatest possible zoom level. You can specify padding, in order to inset the bounding box from the map view's edges. The returned CameraUpdate has a bearing of 0 and a tilt of 0.
找出2个点的边界框并给出最西南点和最东北点
例子:
map.animateCamera(CameraUpdateFactory.newLatLngBounds(new LatLngBounds(southWest,northEast),10));
要获得边界框,您需要遍历您的点并找到最大/最小 lat/lng
例子:
for(//for loop){
LatLng point = new LatLng(lat,lng)
if(point.getLatitude() > maxLat){
maxLat = point.getLatitude();
}
if(point.getLatitude() < minLat){
minLat = point.getLatitude();
}
if(point.getLongitude() > maxLon){
maxLon = point.getLongitude();
}
if(point.getLongitude() < minLon){
minLon = point.getLongitude();
}
}
northEast = new LatLng(maxLat,maxLon);
southWest = new LatLng(minLat,minLon);