Nima, gibt es verschiedene Wege, dieses Verhalten zu erreichen, indem sie Werte in Kamerapositionen zwicken.
Zum Beispiel haben Sie 2 geo location latlng Informationen zur Verfügung, UserLocation und DestinationLocation finden den Mittelpunkt dieses Ortes und setzen das Kameraziel auf diesen. Und dann können Sie die Kamera auf Zoom-Ebene verschieben, die beide Geolocation mit der richtigen Polsterung von oben und unten abdecken, indem Sie den Peilungswert angeben.
//First build the bounds using the builder
LatLngBounds.Builder builder = new LatLngBounds.Builder();
LatLngBounds bounds;
builder.include(userLocation);
builder.include(destinationLocation);
bounds = builder.build();
// define value for padding
int padding =20;
//This cameraupdate will zoom the map to a level where both location visible on map and also set the padding on four side.
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds,padding);
mMap.moveCamera(cu);
// now lets make the map rotate based on user location
// for that we will add the bearing to the camera position.
//convert latlng to Location object
Location startLocation = new Location("startingPoint");
startLocation.setLatitude(userLocation.latitude);
startLocation.setLongitude(userLocation.longitude);
Location endLocation = new Location("endingPoint");
endLocation.setLatitude(destinationLocation.latitude);
endLocation.setLongitude(destinationLocation.longitude);
//get the bearing which will help in rotating the map.
float targetBearing = startLocation.bearingTo(endLocation);
//Now set this values in cameraposition
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(bounds.getCenter())
.zoom(mMap.getCameraPosition().zoom)
.bearing(targetBearing)
.build();
mMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
poste deine layout.xml-Datei. –
@ChiragSavsani warum? Dies hat nichts mit dem Layout zu tun, vorausgesetzt, ein Support-Map-Fragment wird in ein Framelayout geladen. – Nima