rionymous_
rionymous_

Reputation: 11

error getMap() in android studio map.setMyLocationEnabled(true);

hello guys, please help me. I don't know what to do

I have also done the suggestion that has been given android studio

Upvotes: 0

Views: 118

Answers (2)

Vishal Chhodwani
Vishal Chhodwani

Reputation: 2577

These both errors are different.

  1. getmap() is deprecated. you have to use mapFragment.getMapAsync(this)
  2. setMyLocationEnable needs to check for run time permission of ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION.

for issue 1 try this:

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

For issue 2 use this

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);
}

Upvotes: 0

Hardik Lakhani
Hardik Lakhani

Reputation: 1564

getMap() is deprecated. Use getMapAsync() like below.

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

Upvotes: 1

Related Questions