0
嘿我試圖讓位置服務工作在Android Studio和.getMapAsync(這)不斷崩潰的應用程序。如果任何人都可以告訴我我搞亂了什麼,我會非常感激。如何解決getMapAsync(this)崩潰?
GoogleMap memberMap;
GoogleApiClient memberAPI;
LocationRequest memberLocationRequest;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (googleServicesAvailable()) {
setContentView(R.layout.activity_main_page);
onMapReady(memberMap);
} else {
Toast.makeText(this, "Google services not available", Toast.LENGTH_LONG);
//to be done
}
}
@Override
public void onMapReady(GoogleMap googleMap) {
memberMap = googleMap;
//memberMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
SupportMapFragment mapFragment =(SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.mapfragment);
mapFragment.getMapAsync(this);
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
if(!locationManager.isProviderEnabled((LocationManager.GPS_PROVIDER))){
buildAlertMessageNoGps();
}
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
buildGoogleApiClient();
memberMap.setMyLocationEnabled(true);
}
}
}
使用LogCat檢查與您的崩潰相關的Java堆棧跟蹤:https://stackoverflow.com/questions/23353173/uncomfort-myapp-has-stopped-how-can-i-solve-this – CommonsWare