【发布时间】:2017-05-27 20:36:44
【问题描述】:
嘿,我正在尝试让位置服务在 Android Studio 上运行,而 .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 堆栈跟踪:stackoverflow.com/questions/23353173/…
标签: java android google-maps maps