我每次運行它,我得到這個錯誤信息「java.lang.IllegalStateException:之前的onCreate系統不可用活動服務()」讓用戶地理定位API 23
我需要得到用戶的經度和因此我可以將其用於我的應用程序的其餘部分,但我無法弄清楚如何克服此錯誤。
public class map extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
private FloatingActionButton plus;
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
double longitude = location.getLongitude();
double latitude = location.getLatitude();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
plus = (FloatingActionButton) findViewById(R.id.newPlace);
plus.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
startActivity(new Intent(map.this, newPlacePop.class));
}
});
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
LatLng currentPosition = new LatLng(latitude, longitude);
float zoomLevel = 16; //This goes up to 21
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(currentPosition, zoomLevel));
}
}