Cannot see the blue dot and circle at Mylocation Maps

偶尔善良 提交于 2019-12-09 03:58:53

问题


I want google maps to show the location of the user centered at the map as at the image 1 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


回答1:


Try Code samples of Google.

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

  • MyLocationDemoActivity: Using the My Location layer, including runtime permissions
  • LocationSourceDemoActivity: Using a custom LocationSource

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.

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

Hope this helps!



来源:https://stackoverflow.com/questions/39431892/cannot-see-the-blue-dot-and-circle-at-mylocation-maps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!