android - 根据方位旋转谷歌地图,中心有固定标记
问题描述
我正在尝试在我的应用程序中实现谷歌地图。
要求:
驾驶时,我的标记图标应固定在屏幕中心(始终朝北),而地图应在用户打开街道时左右移动并旋转。
我是如何尝试做到的
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);
}
结果:
标记在路径上移动,但摄像头本身不会根据驾驶员在街道上的转弯移动。我希望我能够让事情变得可以理解。请帮助解决可能出现的问题或更好的解决方案。谢谢
解决方案
推荐阅读
- android - Android 应用程序链接:Xamarin 应用程序未在 https URI 上打开
- mongodb - 从聚合 mogodb 中的对象创建数组
- asp.net - 无法使用 CopyTo(Datastream) 在 asp.net 核心中保存图片
- python - 为什么 OpenCV SimpleBlobDetector 不能检测到这张图片中的斑点?
- php - 通过 Laravel 中的中间件转发请求
- java - 如何将 Tomcat 重写阀添加到 Spring Boot 2.0 应用程序
- asp.net-core - 调用 RequestClientCredentialsTokenAsync 后,访问令牌在访问令牌中不包含“子”声明
- mysql - SQL过滤查询;如何为一个国家(法国)而不是其他国家(选定的欧洲国家)包含某些内容
- spring-cloud-contract - 将重复的正则表达式提取到 Spring Cloud Contract 中的 util 类
- r - group_by 过滤到至少共享一个匹配值的组