mre*_*rek 5 android google-maps google-maps-android-api-2
我想强迫相机表现得像你正在使用导航,这意味着当你向左旋转90°时,相机做同样的事情.
我有一张谷歌地图,其中显示了我的位置(作为蓝点).
mGoogleMap.setMyLocationEnabled(true);
Run Code Online (Sandbox Code Playgroud)
当我移动时,蓝点带有一个箭头,显示我当前的方位.我想得到这个方面.
我使用FusedLocationApi获取当前位置:
currentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
Run Code Online (Sandbox Code Playgroud)
下面的代码是将相机设置为当前位置的动画,但没有轴承.我可以添加轴承,但我不知道它的价值.
@Override
public void onLocationChanged(Location location) {
LatLng latLng = new LatLng( location.getLatitude(), location.getLongitude() );
mGoogleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mGoogleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
}
Run Code Online (Sandbox Code Playgroud)
你知道如何获得当前的位置方向吗?我无法找到任何适当的信息.我非常感谢你能给我的任何帮助.
谢谢
我想你可以尝试使用getOrientation(R, orientation)(并调整为真北)get the device rotation.你可以参考这里.
此外,请使用此处的CameraPosition课程来调整相机位置.
编辑:我甚至找到了更好的解决方案.getBearing()在Location类中使用方法.
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));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10176 次 |
| 最近记录: |