android studio map.setMyLocationEnabled(true)中的错误getMap();

时间:2018-01-31 06:10:36

标签: javascript android google-maps

大家好,请帮帮我。我不知道该怎么做

我也完成了findall(Score, clause(test(5, Score), Body), Scores), max_member(MaxScore, Scores), test(5, MaxScore).

的建议

2 个答案:

答案 0 :(得分:1)

不推荐使用getMap()。使用如下的getMapAsync()。

MapFragment mapFragment = (MapFragment) getFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

答案 1 :(得分:0)

这两个错误都不同。

  1. getmap()已弃用。你必须使用mapFragment.getMapAsync(this)
  2. setMyLocationEnable需要检查ACCESS_COARSE_LOCATIONACCESS_FINE_LOCATION的运行时权限。
  3. 问题1的

    试试这个:

    mapFragment.getMapAsync(new OnMapReadyCallback(){
        @Override
        public void onMapReady(GoogleMap googleMap) {
            map = googleMap;
        }
    });
    

    对于问题2,请使用此

    if (googleMap != null) {
        if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                        && ActivityCompat.checkSelfPermission(getActivity(), 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;
        }
        googleMap.setMyLocationEnabled(true);
    }