欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android 使用地圖時(shí)的權(quán)限請(qǐng)求方法

 更新時(shí)間:2018年07月31日 09:39:59   作者:louyxlovess  
今天小編就為大家分享一篇Android 使用地圖時(shí)的權(quán)限請(qǐng)求方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

在初始化自己位置的時(shí)候請(qǐng)求定位權(quán)限:

Constants.ACCESS_FINE_LOCATION_COMMANDS_REQUEST_CODE是自定義的常量值==0x01

if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
   != PackageManager.PERMISSION_GRANTED) {
  //申請(qǐng)WRITE_EXTERNAL_STORAGE權(quán)限
  ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, Constants.ACCESS_FINE_LOCATION_COMMANDS_REQUEST_CODE);
 } else {
  /**
  * 初始化用戶位置
  */
  setMyLoctionPicture();
 }
/**
  * 初始化用戶位置
  */
 public void setMyLoctionPicture(){
  LogUtils.d(TAG,"setMyLocationPicture() is running");

  if(aMap==null){
   aMap=mapview.getMap();
  }
  MyLocationStyle locationStyle = new MyLocationStyle();
  locationStyle.myLocationIcon(BitmapDescriptorFactory.fromResource(R.mipmap.location_marker));
  locationStyle.strokeColor(Color.BLACK);
  locationStyle.radiusFillColor(Color.argb(100, 0, 0, 100));
  locationStyle.strokeWidth(1.0f);
  aMap.setMyLocationStyle(locationStyle);
  aMap.setLocationSource(this);
  UiSettings uiSettings = aMap.getUiSettings();
  uiSettings .setMyLocationButtonEnabled(true);

  aMap.setMyLocationEnabled(true);
  aMap.setInfoWindowAdapter(this);
  aMap.setOnMarkerClickListener(this);

 }

這樣是確保在Android高版本時(shí)定位權(quán)限不會(huì)被屏蔽;導(dǎo)致定位和導(dǎo)航用不了情況。

以上這篇Android 使用地圖時(shí)的權(quán)限請(qǐng)求方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論