我正在尝试在我的应用程序中实现google maps。
要求:
在驾驶时,我的标记图标应固定在屏幕中央(始终朝北),而地图应在左右方向上向左移动并在用户打开街道时旋转。
我如何尝试做到
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(position, 5));
float bearing = getBearing(Lastposition,newPosition);
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(newPosition)
.zoom(15)
.bearing(bearing)
.tilt(0)
.build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
public static float getBearing(LatLng from, LatLng to) {
Location fromLocation = new Location("");//provider name is unnecessary
fromLocation.setLatitude(from.latitude);
fromLocation.setLongitude(from.longitude);
Location toLocation = new Location("");//provider name is unnecessary
toLocation.setLatitude(to.latitude);
toLocation.setLongitude(to.longitude);
Log.i("Bearing",fromLocation.bearingTo(toLocation)+"");
return fromLocation.bearingTo(toLocation);
}
结果:
标记在路径上移动,但相机本身不会根据驾驶员在街道上的转弯而移动。我希望我能够使事情变得容易理解。请帮助解决可能出现的问题或更好的解决方案。谢谢