在Mylocation地图上看不到蓝点和圆圈 [英] Cannot see the blue dot and circle at Mylocation Maps

查看:142
本文介绍了在Mylocation地图上看不到蓝点和圆圈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望Google地图显示用户位于地图上的位置,如图所示1

这是我的代码片段:

  public class MapFragment extends Fragment implements OnMapReadyCallback {
GoogleMap googleMap;
MapView mapView;
查看myview;
$ b $ public查看onCreateView(LayoutInflater inflater,ViewGroup容器,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);


返回myview;
}

@Override
public void onMapReady(GoogleMap map){
googleMap = map;
列表< 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:考虑调用
// ActivityCompat#requestPermissions
//请求失踪权限,然后重写
// public void onRequestPermissionsResult(int requestCode,String [] permissions,
// int [] grantResults)
//处理用户授予权限的情况。有关更多详细信息,请参阅文档
//获取ActivityCompat#requestPermissions。
return;
}
googleMap.setMyLocationEnabled(true);
googleMap.getUiSettings()。setMyLocationButtonEnabled(true);






$ b

但是当我在模拟器或手机上执行它时,我只能得到没有任何内容的地图,如image2

解决方案

尝试使用Google的代码示例。 $ b


GitHub上的一个href =https://github.com/googlemaps/android-samples/blob/master/ApiDemos =nofollow noreferrer> ApiDemos存储库包含示例,演示在地图上使用位置:






  • 您可以随时检查并比较您的代码与样本代码,以验证或检查您的实施是否正确。



    希望这有助于!


    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

    解决方案

    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.

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

    Hope this helps!

    这篇关于在Mylocation地图上看不到蓝点和圆圈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆