使用 Android 传感器和 google 地图

Working with Android Sensor with google maps

我是第一次在 Android 平台上开发应用程序并尝试将传感器与 google 地图连接。单独地,传感器和 google 地图工作正常,但是,当我尝试通过 Fragment 连接它时,它给出了一个错误。

错误:

incompatible types: cannot be converted to OnMapReadyCallback

这是我的示例代码:

public void onSensorChanged(SensorEvent event) { 
  if (event.sensor.getType() == Sensor.TYPE_LIGHT) {
     textLIGHT_reading.setText("LIGHT1: " + event.values[0]);
     updateCamera(event.values[0]);
  }
}

private void updateCamera(float degree) {
  if (mMap == null) {
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
  }
}

感谢您的帮助。

看来我使用了错误的库,我重新创建了项目并更改了代码,因为第一次 google 地图下载需要时间,所以最好在 else 语句中编写代码。

if ( mMap == null){ 
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
            Log.d("mapFragment","Degree--" + googleMap1);
            mapFragment.getMapAsync(this);
            } else {
            Log.d("MapNOTNULL","Degree---" + mMap);
              mMap.animateCamera(CameraUpdateFactory.zoomTo(bearing));
            }