Search in sources :

Example 1 with AMapLocationClient

use of com.amap.api.location.AMapLocationClient in project YourEyes by SevenLJY.

the class PoiSearchActivity method initLocation.

/**
     * 初始化定位
     * */
private void initLocation() {
    mLocationClient = new AMapLocationClient(this.getApplicationContext());
    //设置定位参数
    mLocationClient.setLocationOption(getDefaultOption());
    //设置定位监听
    mLocationClient.setLocationListener(locationListener);
}
Also used : AMapLocationClient(com.amap.api.location.AMapLocationClient)

Example 2 with AMapLocationClient

use of com.amap.api.location.AMapLocationClient in project Collar by CodeZsx.

the class PostActivity method startLocation.

private void startLocation() {
    requestPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.READ_PHONE_STATE);
    mBinding.tvAddress.setText("定位中...");
    AMapLocationListener mLocationListener = new AMapLocationListener() {

        @Override
        public void onLocationChanged(AMapLocation aMapLocation) {
            if (aMapLocation != null) {
                if (aMapLocation.getErrorCode() == 0) {
                    Message message = new Message();
                    message.what = MESSAGE_LOCATION_RESULT;
                    message.obj = aMapLocation.getAddress();
                    mHandler.sendMessage(message);
                } else {
                    // 定位失败时,可通过ErrCode(错误码)信息来确定失败的原因,errInfo是错误信息,详见错误码表。
                    Log.e("AmapError", "location Error, ErrCode:" + aMapLocation.getErrorCode() + ", errInfo:" + aMapLocation.getErrorInfo());
                }
            }
        }
    };
    mLocationClient = new AMapLocationClient(getApplicationContext());
    mLocationClient.setLocationListener(mLocationListener);
    // 初始化AMapLocationClientOption对象
    AMapLocationClientOption mLocationOption = new AMapLocationClientOption();
    // 设置高精度定位模式:会同时使用网络定位和GPS定位,优先返回最高精度的定位结果,以及对应的地址描述信息
    mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
    // //设置低功耗定位模式:不会使用GPS和其他传感器,只会使用网络定位(WIFI和基站定位)
    // mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Battery_Saving);
    // //设置仅用设备定位模式:不需要连接网络,只使用GPS进行定位,这种模式下不支持室内环境的定位,自v2.9.0版本支持返回地址描述信息
    // mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Device_Sensors);
    // 设置获取3s内精度最高的一次定位结果
    mLocationOption.setOnceLocationLatest(true);
    // 设置是否返回地址信息,默认返回地址信息
    mLocationOption.setNeedAddress(true);
    // 给定位客户端对象设置定位参数
    mLocationClient.setLocationOption(mLocationOption);
    // 启动定位
    mLocationClient.startLocation();
}
Also used : AMapLocation(com.amap.api.location.AMapLocation) AMapLocationClient(com.amap.api.location.AMapLocationClient) Message(android.os.Message) AMapLocationClientOption(com.amap.api.location.AMapLocationClientOption) AMapLocationListener(com.amap.api.location.AMapLocationListener)

Example 3 with AMapLocationClient

use of com.amap.api.location.AMapLocationClient in project summer-android by cn-cerc.

the class ClockInActivity method activate.

@Override
public void activate(OnLocationChangedListener onLocationChangedListener) {
    mListener = onLocationChangedListener;
    if (mlocationClient == null) {
        mlocationClient = new AMapLocationClient(ClockInActivity.this);
        mLocationOption = new AMapLocationClientOption();
        // 设置定位监听
        mlocationClient.setLocationListener(this);
        // 设置为高精度定位模式
        mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
        mLocationOption.setInterval(60000);
        // 设置定位参数
        mlocationClient.setLocationOption(mLocationOption);
        mlocationClient.startLocation();
    }
}
Also used : AMapLocationClient(com.amap.api.location.AMapLocationClient) AMapLocationClientOption(com.amap.api.location.AMapLocationClientOption)

Example 4 with AMapLocationClient

use of com.amap.api.location.AMapLocationClient in project ttdj by soonphe.

the class HomeFragment method initLocation.

private void initLocation() {
    // 声明AMapLocationClient类对象
    mLocationClient = new AMapLocationClient(this.getContext());
    // 配置定位参数
    AMapLocationClientOption option = new AMapLocationClientOption();
    // 高精度定位模式:会同时使用网络定位和GPS定位
    option.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
    option.setOnceLocation(true);
    mLocationClient.setLocationOption(option);
    // 设置 定位回调监听器
    mLocationClient.setLocationListener(new AMapLocationListener() {

        @Override
        public void onLocationChanged(AMapLocation aMapLocation) {
            if (aMapLocation != null) {
                if (aMapLocation.getErrorCode() == 0) {
                    /*
                        //基础定位信息
                         amapLocation.getCountry();//国家信息
                         amapLocation.getProvince();//省信息
                         amapLocation.getCity();//城市信息
                         amapLocation.getDistrict();//城区信息
                         amapLocation.getStreet();//街道信息
                         amapLocation.getStreetNum();//街道门牌号信息
                         //获取定位时间
                         SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                         Date date = new Date(amapLocation.getTime());
                         */
                    String city = aMapLocation.getCity();
                    String cou = aMapLocation.getDistrict();
                    Log.e("onLocationChanged", "city: " + city);
                    Log.e("onLocationChanged", "district: " + cou);
                    String location = StringUtils.extractLocation(city, cou);
                    tvCity.setText(location);
                    CacheUtils.getInstance().put(AMAP_LOCATION, location);
                } else {
                    // 定位失败
                    currentCity = "定位失败";
                    tvCity.setText(currentCity);
                }
            }
        }
    });
    mLocationClient.startLocation();
}
Also used : AMapLocationClient(com.amap.api.location.AMapLocationClient) AMapLocation(com.amap.api.location.AMapLocation) AMapLocationClientOption(com.amap.api.location.AMapLocationClientOption) AMapLocationListener(com.amap.api.location.AMapLocationListener)

Example 5 with AMapLocationClient

use of com.amap.api.location.AMapLocationClient in project Atom_Android by Rogrand-Dev.

the class MyCityActivity method initLocation.

/**
 * 初始化定位
 */
private void initLocation() {
    // 初始化client
    mLocationClient = new AMapLocationClient(this.getApplicationContext());
    locationOption = mPresenter.getDefaultOption();
    // 设置定位参数
    mLocationClient.setLocationOption(locationOption);
    // 设置定位监听
    mLocationClient.setLocationListener(this);
}
Also used : AMapLocationClient(com.amap.api.location.AMapLocationClient)

Aggregations

AMapLocationClient (com.amap.api.location.AMapLocationClient)17 AMapLocationClientOption (com.amap.api.location.AMapLocationClientOption)10 AMapLocation (com.amap.api.location.AMapLocation)4 AMapLocationListener (com.amap.api.location.AMapLocationListener)4 Message (android.os.Message)1