我想强制相机的行为就像您正在使用导航一样,这意味着当您向左旋转 90° 时,相机会执行相同的操作。
我有一个谷歌地图,其中显示了我的位置(作为蓝点)。
mGoogleMap.setMyLocationEnabled(true);
当我移动时,蓝点带有箭头,显示我当前的方位。我想要这个轴承。
我正在使用获取当前位置融合位置API:
currentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
下面的代码是将相机动画到当前位置,but没有轴承。我可以添加轴承,但我不知道其价值。
@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)
(并调整为正北)get the device rotation
。您可以参考here.
另外,使用CameraPosition
class here调整相机位置。
编辑:我什至找到了更好的解决方案。使用getBearing()
中的方法Location 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));
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)