不兼容的onMapReady()函数类型

时间:2016-10-07 10:39:56

标签: java android google-maps

我尝试将我的OnMapReadyCallback设置为get map Async参数。但是android告诉我它需要GoogleMap对象,在mapReady()的文档中是无效的。

下面的代码
private void initilizeMap() {
    if (googleMap == null) {
        googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                R.id.map)).getMapAsync(this);

        // check if map is created successfully or not
        if (googleMap == null) {
            Toast.makeText(getApplicationContext(),
                    "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                    .show();
        }
    }
}

@Override
public void onMapReady(GoogleMap map) {
    map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
    map.setTrafficEnabled(true);
    map.setIndoorEnabled(true);
    map.setBuildingsEnabled(true);
    map.getUiSettings().setZoomControlsEnabled(true);
}

2 个答案:

答案 0 :(得分:2)

getMapAsync不会返回GoogleMap个对象(documentation)。您可以像这样初始化googleMap对象:

private void initilizeMap() {
    ((MapFragment) getFragmentManager().findFragmentById(
            R.id.map)).getMapAsync(this);
}

@Override
public void onMapReady(GoogleMap map) {
    googleMap = map;
    map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
    map.setTrafficEnabled(true);
    map.setIndoorEnabled(true);
    map.setBuildingsEnabled(true);
    map.getUiSettings().setZoomControlsEnabled(true);
}

答案 1 :(得分:0)

您可以尝试使用此代码。

@Controller
public class AdminCtrl {

private static String UPLOAD_LOCATION = "C:/temp/";
@Autowired
FileValidator fileValidator;

@InitBinder("fileBucket")
protected void initBinderFileBucket(WebDataBinder binder) {
    binder.setValidator(fileValidator);
}
//--------------------------POST IMAGE -------------------------------------   -----------------------------

 @RequestMapping(value = "/administration/parametres/profile", method = RequestMethod.POST)
public String profilePage(@Valid FileBucket fileBucket,
        BindingResult result, ModelMap model) throws IOException {
    if (result.hasErrors()) {
        System.out.println("validation errors");
        return "redirect:/administration/parametres/profile?error";
    } else {
        System.out.println("Fetching file");
        MultipartFile multipartFile = fileBucket.getFile();
         Now do something with file...
        FileCopyUtils.copy(fileBucket.getFile().getBytes(), new File(UPLOAD_LOCATION + fileBucket.getFile().getOriginalFilename()));
        String fileName = multipartFile.getOriginalFilename();
        model.addAttribute("fileName", fileName);
        return "redirect:/administration/parametres/profile?success";
    }
}