我想强制相机的行为就像您正在使用导航一样,这意味着当您向左旋转 90° 时,相机会做同样的事情。
我有一个 Google map ,其中显示了我的位置(作为蓝点)。
mGoogleMap.setMyLocationEnabled(true);
当我移动时,蓝点带有箭头,显示我当前的方位。我想得到这个方位。
我正在使用 FusedLocationApi 获取我的当前位置:
currentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
下面的代码是将相机动画化到当前位置,但没有方位。我可以添加轴承,但我不知道值。
@Override
public void onLocationChanged(Location location) {
LatLng latLng = new LatLng( location.getLatitude(), location.getLongitude() );
mGoogleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mGoogleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
}
你知道如何获取当前位置方向吗?我找不到任何关于那个的适当信息。如果您能给我任何帮助,我将不胜感激。
谢谢
最佳答案
我认为您可以尝试使用 getOrientation(R, orientation)
(并针对真北进行调整)获取设备旋转
。可以引用here .
此外,使用 CameraPosition
类 here调整相机位置。
编辑:我什至找到了更好的解决方案。在 Location 中使用 getBearing()
方法类(class)。
if (location.hasBearing()) {
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(latLng) // Sets the center of the map to current location
.zoom(15) // Sets the zoom
.bearing(location.getBearing()) // Sets the orientation of the camera to east
.tilt(0) // Sets the tilt of the camera to 0 degrees
.build(); // Creates a CameraPosition from the builder
mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
关于Android 谷歌地图 API v2 : get my bearing location,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28951974/