示例#1
0
  /** 初始化方向传感器 */
  private void initOrientationListener() {
    orientationListener = new MyOrientationListener(this);
    orientationListener.start();
    orientationListener.setOrientationListener(
        new MyOrientationListener.onOrientationListener() {
          @Override
          public void onOrientationChanged(float x) {
            direction = x;

            if (locationListener.getLatLng() == null || mapView == null) return;
            MyLocationData data =
                new MyLocationData.Builder()
                    .accuracy(locationListener.getRadius())
                    .direction(direction)
                    .latitude(locationListener.getLatLng().latitude)
                    .longitude(locationListener.getLatLng().longitude)
                    .build();
            map.setMyLocationData(data);
          }
        });
  }
示例#2
0
 @Override
 protected void onStop() {
   orientationListener.stop();
   super.onStop();
 }