Hey I'm trying to get location services to work on Android Studio and .getMapAsync(this) keeps crashing the app. If anyone can show me where I'm messing up I'd greatly appreciate it.
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);
}
}
}