luciocamilo
luciocamilo

Reputation: 80

Cannot see the blue dot and circle at Mylocation Maps

I want google maps to show the location of the user centered at the map as at the image 1 Blue dot and circle And this is my Fragment Code:

public class MapFragment extends Fragment implements OnMapReadyCallback {
GoogleMap googleMap;
MapView mapView;
View myview;

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    myview = inflater.inflate(R.layout.map_layout, container, false);

    mapView = (MapView) myview.findViewById(R.id.map);
    mapView.onCreate(savedInstanceState);
    mapView.onResume();
    mapView.getMapAsync(this);


    return myview;
}

@Override
public void onMapReady(GoogleMap map) {
    googleMap = map;
    List<EscolasMaps> escolasMapsList = new ArrayList<EscolasMaps>();
    //buscarEscolas();
    if (ActivityCompat.checkSelfPermission(this.getActivity(), Manifest.permission.ACCESS_FINE_LOCATION)
            != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this.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);
    googleMap.getUiSettings().setMyLocationButtonEnabled(true);

}

}

But when I execute it at the emulator, or at my phone, I only get the map whithout anything as show at image2 enter image description here

Upvotes: 0

Views: 2097

Answers (1)

Mr.Rebot
Mr.Rebot

Reputation: 6791

Try Code samples of Google.

The ApiDemos repository on GitHub includes samples that demonstrate the use of location on a map:

You can use the My Location layer and the My Location button to provide your user with their current position on the map.

Note: Before enabling the My Location layer, you must ensure that you have the required runtime location permission.

Enable the My Location layer on the map as follows:

mMap.setMyLocationEnabled(true);

When the My Location layer is enabled, the My Location button appears in the top right corner of the map. When a user clicks the button, the camera centers the map on the current location of the device, if it is known. The location is indicated on the map by a small blue dot if the device is stationary, or as a chevron if the device is moving.

enter image description here

You can always check and compare your codes to the sample code to verify or check if your implementation is correct.

Hope this helps!

Upvotes: 2

Related Questions