我想使用內(nèi)部函數(shù)內(nèi)部的類成員我嘗試將變量設(shè)置為全局變量,但出現(xiàn)錯(cuò)誤“預(yù)期的類或接口”@Override public void onMapReady(GoogleMap googleMap) { // Add a marker in current location, // and move the map's camera to the same location. //Location currentLocation = LocationServices.FusedLocationApi.getLastLocation(googleApiClient); FusedLocationProviderClient fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, MY_PERMISSIONS_REQUEST_ACCESS_LOCATION); }else { mFusedLocationClient.getLastLocation().addOnSuccessListener(new OnSuccessListener<Location>() { @Override public void onSuccess(Location location) { wayLongitude = location.getLongitude(); wayLatitude = location.getLatitude(); /*LatLng sydney = new LatLng(wayLatitude, wayLongitude); googleMap.addMarker(new MarkerOptions().position(sydney) .title("Marker in Sydney")); googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));*/ } }); }我希望能夠在“OnSuccess”函數(shù)中執(zhí)行“googleMap.addMarker”。我該怎么做?
1 回答

UYOU
TA貢獻(xiàn)1878條經(jīng)驗(yàn) 獲得超4個(gè)贊
您需要將 googleMap 參數(shù)聲明為最終參數(shù):
public void onMapReady(final GoogleMap googleMap) { //... }
添加回答
舉報(bào)
0/150
提交
取消