I have been trying to make Google maps display my current location, but it just shows me the whole map. Please how do I go about this, here is my code
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(1000);
mLocationRequest.setFastestInterval(1000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mMap.animateCamera(CameraUpdateFactory.zoomTo(11));
if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
if(ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){
}else{
checkLocationPermission();
}
}
mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper());
mMap.setMyLocationEnabled(true);
}
private void checkLocationPermission() {
if(ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED){
if (ActivityCompat.shouldShowRequestPermissionRationale(this, android.Manifest.permission.ACCESS_FINE_LOCATION)) {
new android.app.AlertDialog.Builder(this)
.setTitle("give permission")
.setMessage("give permission message")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
ActivityCompat.requestPermissions(WorkerMap.this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, 1);
}
})
.create()
.show();
}
else{
ActivityCompat.requestPermissions(WorkerMap.this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, 1);
}
}
}
LocationCallback mLocationCallback = new LocationCallback(){
@Override
public void onLocationResult(LocationResult locationResult) {
for(Location location : locationResult.getLocations()){
if(getApplicationContext()!=null){
mLastLocation = location;
LatLng latLng = new LatLng(location.getLatitude(),location.getLongitude());
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(11));
}
}
}
};
It's supposed to get my current location, but it's not doing that. What might be wrong please