Android Google 地图 - 获取当前倾斜度、方位角和缩放比例
Android Google Maps - Get current tilt, bearing and zoom
我正在 google 地图上构建一个 android 应用程序,它显示用户的当前位置,并不断更新它。
现在,我想要的是,如果作为用户,我缩小地图并改变方位,我希望我的相机保持缩放、方位和倾斜。
这是我目前使用的-
public void setupLocationOnMap(){
if (mLastLocation != null) {
LatLng myLatLng = new LatLng(mLastLocation.getLatitude(),mLastLocation.getLongitude());
if(firstTimeSetup) {
cameraPosition = new CameraPosition.Builder().target(myLatLng).zoom(17).bearing(-30).tilt(30).build();
firstTimeSetup = false;
} else {
cameraPosition = new CameraPosition.Builder().target(myLatLng).build();
}
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
}
此函数在 onLocationChanged(Location location) 回调中被调用。我想要实现的是,在 'else' 部分,如果用户更改了他的变焦或方位,我想在相机中保持该变焦、方位和倾斜。我不想在每次更新位置时将相机设置为某个预定义值。我想获取当前的缩放、方位和倾斜,并将相机设置为那个,只有 (lat,lang) 需要更新。
非常感谢任何帮助。
您可以获得当前相机位置并使用这些值:https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap.html#getCameraPosition()
Gets the current position of the camera.
The CameraPosition returned is a snapshot of the current position, and will not automatically update when the camera moves
所以你可以这样做:
CameraPosition currentposition=googlemap.getCameraPosition();
currentposition.tilt
currentposition.bearing
currentposition.zoom
您现在拥有所有需要的值!
我正在 google 地图上构建一个 android 应用程序,它显示用户的当前位置,并不断更新它。
现在,我想要的是,如果作为用户,我缩小地图并改变方位,我希望我的相机保持缩放、方位和倾斜。
这是我目前使用的-
public void setupLocationOnMap(){
if (mLastLocation != null) {
LatLng myLatLng = new LatLng(mLastLocation.getLatitude(),mLastLocation.getLongitude());
if(firstTimeSetup) {
cameraPosition = new CameraPosition.Builder().target(myLatLng).zoom(17).bearing(-30).tilt(30).build();
firstTimeSetup = false;
} else {
cameraPosition = new CameraPosition.Builder().target(myLatLng).build();
}
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
}
此函数在 onLocationChanged(Location location) 回调中被调用。我想要实现的是,在 'else' 部分,如果用户更改了他的变焦或方位,我想在相机中保持该变焦、方位和倾斜。我不想在每次更新位置时将相机设置为某个预定义值。我想获取当前的缩放、方位和倾斜,并将相机设置为那个,只有 (lat,lang) 需要更新。
非常感谢任何帮助。
您可以获得当前相机位置并使用这些值:https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap.html#getCameraPosition()
Gets the current position of the camera. The CameraPosition returned is a snapshot of the current position, and will not automatically update when the camera moves
所以你可以这样做:
CameraPosition currentposition=googlemap.getCameraPosition();
currentposition.tilt
currentposition.bearing
currentposition.zoom
您现在拥有所有需要的值!