2016-10-20 106 views
0

我第一次在Android平台上开发应用程序并试图将传感器连接到Google地图。个别地,传感器和谷歌地图工作正常,但是,当我尝试连接它通过Fragment,它会给出错误。使用谷歌地图Android传感器

错误:

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); 
    } 
} 

感谢您的任何帮助。

+0

你的片段实现了'OnMapReadyCallback'吗? – siger

+0

,如果你可能请发布logcat – 7geeky

回答

0

看来我使用的是错误的库,我重新创建了项目并更改了代码,因为第一次使用谷歌地图需要花费时间下载,以便在其他语句中编写代码。

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)); 
      }