【问题标题】:Android maps: Getting map to orient in direction the phone is facingAndroid地图:让地图朝向手机所面对的方向
【发布时间】:2014-06-25 15:33:56
【问题描述】:

谁能告诉我我可以用什么来完成这个?我无法确定手机的朝向以及如何旋转地图的相机视图以反映手机朝向的变化。

【问题讨论】:

    标签: java android google-maps mobile


    【解决方案1】:

    使用SensorManager.getOrientation(float[] R, float[] values) 获取手机的罗盘方向。您必须阅读documentation for getOrientation(),这有点复杂,我将把探索留给您:)

    一旦你有了手机的航向(方向),你就可以使用如下函数来旋转你的地图(取自here):

    public void updateCamera(float bearing) {
                CameraPosition currentPlace = new CameraPosition.Builder()
                        .target(new LatLng(centerLatitude, centerLongitude))
                        .bearing(bearing).tilt(65.5f).zoom(18f).build();
                googleMap.moveCamera(CameraUpdateFactory.newCameraPosition(currentPlace));
    
        }
    

    如果您有任何其他问题,请告诉我!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-29
      • 2016-10-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多