onSensorChanged调用我的方法时如何旋转标记?我尝试了这段代码,但我得到了 NullPointerException。我声明mMap为全局变量并将其加载到 onMapReady 中。我想在我的onSensorChanged方法中使用它。我该如何解决?
我收到了这个错误:
java.lang.NullPointerException:尝试调用虚拟方法 'com.google.android.gms.maps.model.Marker com.google.android.gms.maps.GoogleMap.addMarker(com.google.android.gms.maps.model .MarkerOptions)' 在空对象引用上
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.getUiSettings().setZoomControlsEnabled(true);
latLng_dest = getIntent().getExtras().getParcelable("latLng_dest");
Log.d("LatLng_dest : ", latLng_dest.toString());
if (ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, LOCATION_REQUEST);
return;
}
mMap.setMyLocationEnabled(true);
mMap.getUiSettings().setMyLocationButtonEnabled(false);
// Call our direction function
getDeviceLocation();
}
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor == mRotationSensor) {
if (event.values.length > 4) {
float[] truncatedRotationVector = new float[4];
System.arraycopy(event.values, 0, truncatedRotationVector, 0, 4);
updateSensor(truncatedRotationVector);
} else {
updateSensor(event.values);
}
}
}
}
慕运维8079593
撒科打诨
相关分类