鉴于以下是我的代码,显示当前位置,其中mLastLocation烘烤为空并且不显示我当前的位置,并且不向其添加任何标记。
@Override
public void onConnected(@Nullable Bundle bundle) {
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
Toast.makeText(this, "onConnected Method"+String.valueOf(mGoogleApiCLient.isConnected()), Toast.LENGTH_SHORT).show();
Location mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiCLient);
Toast.makeText(this, "Currrrrrrrent"+mLastLocation, Toast.LENGTH_SHORT).show();
if (mLastLocation!=null)
{
latLng=new LatLng(mLastLocation.getLatitude(),mLastLocation.getLongitude());
MarkerOptions markerOptions=new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title("Current Location");
mCurrLocation=mMap.addMarker(markerOptions);
}
mLocationRequest=new LocationRequest();
mLocationRequest.setInterval(5000);
mLocationRequest.setFastestInterval(3000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiCLient,mLocat ionRequest,this);
}