高德地图的简单记录

高德地图的简单记录,没啥,随便记录的,官网上写的已经很详细了

1:获取一次自己所在的位置

public class CeShi extends AppCompatActivity {
    //声明AMapLocationClient类对象
    public AMapLocationClient mLocationClient = null;
    private AMapLocationClientOption aMapLocationClientOption;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        PermissionsUtil.applyPermissions(this, Manifest.permission.ACCESS_COARSE_LOCATION);
        PermissionsUtil.applyPermissions(this, Manifest.permission.ACCESS_FINE_LOCATION);
        setContentView(R.layout.ceshi);
        //声明定位回调监听器
        AMapLocationListener mLocationListener = new AMapLocationListener() {
            @Override
            public void onLocationChanged(AMapLocation aMapLocation) {
                Log.d("CeShi", aMapLocation.toString());
            }
        };
        //初始化定位
        mLocationClient = new AMapLocationClient(getApplicationContext());
        aMapLocationClientOption=new AMapLocationClientOption();
        aMapLocationClientOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Battery_Saving);
        aMapLocationClientOption.setOnceLocation(true);
        mLocationClient.setLocationOption(aMapLocationClientOption);
        //设置定位回调监听
        mLocationClient.setLocationListener(mLocationListener);
        mLocationClient.startLocation();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mLocationClient.stopLocation();
    }
}

你可能感兴趣的:(高德地图的简单记录)