Search in sources :

Example 11 with AMapLocationClientOption

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

the class MyLocationActivity method getDefaultOption.

/**
     * 默认的定位参数
     * */
private AMapLocationClientOption getDefaultOption() {
    AMapLocationClientOption mOption = new AMapLocationClientOption();
    //可选,设置定位模式,可选的模式有高精度、仅设备、仅网络。默认为高精度模式
    mOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
    //可选,设置是否gps优先,只在高精度模式下有效。默认关闭
    mOption.setGpsFirst(true);
    //可选,设置网络请求超时时间。默认为30秒。在仅设备模式下无效
    mOption.setHttpTimeOut(30000);
    //可选,设置定位间隔。默认为2秒
    mOption.setInterval(2000);
    //可选,设置是否返回逆地理地址信息。默认是true
    mOption.setNeedAddress(true);
    //可选,设置是否单次定位。默认是false
    mOption.setOnceLocation(false);
    //可选,设置是否等待wifi刷新,默认为false.如果设置为true,会自动变为单次定位,持续定位时不要使用
    mOption.setOnceLocationLatest(false);
    //可选, 设置网络请求的协议。可选HTTP或者HTTPS。默认为HTTP
    AMapLocationClientOption.setLocationProtocol(AMapLocationClientOption.AMapLocationProtocol.HTTP);
    //可选,设置是否使用传感器。默认是false
    mOption.setSensorEnable(false);
    //可选,设置是否开启wifi扫描。默认为true,如果设置为false会同时停止主动刷新,停止以后完全依赖于系统刷新,定位位置可能存在误差
    mOption.setWifiScan(true);
    //可选,设置是否使用缓存定位,默认为true
    mOption.setLocationCacheEnable(true);
    return mOption;
}
Also used : AMapLocationClientOption(com.amap.api.location.AMapLocationClientOption)

Example 12 with AMapLocationClientOption

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

the class LocationService method getDefaultOption.

/**
     * 默认的定位参数
     * */
private AMapLocationClientOption getDefaultOption() {
    AMapLocationClientOption mOption = new AMapLocationClientOption();
    //可选,设置定位模式,可选的模式有高精度、仅设备、仅网络。默认为高精度模式
    mOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
    //可选,设置是否gps优先,只在高精度模式下有效。默认关闭
    mOption.setGpsFirst(true);
    //可选,设置网络请求超时时间。默认为30秒。在仅设备模式下无效
    mOption.setHttpTimeOut(30000);
    //可选,设置定位间隔。默认为2秒
    mOption.setInterval(2000);
    //可选,设置是否返回逆地理地址信息。默认是true
    mOption.setNeedAddress(true);
    //可选,设置是否单次定位。默认是false
    mOption.setOnceLocation(false);
    //可选,设置是否等待wifi刷新,默认为false.如果设置为true,会自动变为单次定位,持续定位时不要使用
    mOption.setOnceLocationLatest(false);
    //可选, 设置网络请求的协议。可选HTTP或者HTTPS。默认为HTTP
    AMapLocationClientOption.setLocationProtocol(AMapLocationClientOption.AMapLocationProtocol.HTTP);
    //可选,设置是否使用传感器。默认是false
    mOption.setSensorEnable(false);
    //可选,设置是否开启wifi扫描。默认为true,如果设置为false会同时停止主动刷新,停止以后完全依赖于系统刷新,定位位置可能存在误差
    mOption.setWifiScan(true);
    //可选,设置是否使用缓存定位,默认为true
    mOption.setLocationCacheEnable(true);
    return mOption;
}
Also used : AMapLocationClientOption(com.amap.api.location.AMapLocationClientOption)

Example 13 with AMapLocationClientOption

use of com.amap.api.location.AMapLocationClientOption in project Ency by xiarunhao123.

the class MainActivity method initLocation.

/**
 * 定位初始化
 */
private void initLocation() {
    // 初始化定位
    mLocationClient = new AMapLocationClient(mContext);
    // 设置定位回调监听
    mLocationClient.setLocationListener(this);
    mLocationOption = new AMapLocationClientOption();
    // 设置定位模式为高精度模式,Battery_Saving为低功耗模式,Device_Sensors是仅设备模式
    mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
    // 设置是否返回地址信息(默认返回地址信息)
    mLocationOption.setNeedAddress(true);
    // 设置是否只定位一次,默认为false
    mLocationOption.setOnceLocation(false);
    // 设置是否强制刷新WIFI,默认为强制刷新
    mLocationOption.setWifiActiveScan(true);
    // 设置是否允许模拟位置,默认为false,不允许模拟位置
    mLocationOption.setMockEnable(false);
    // 设置定位间隔 单位毫秒
    mLocationOption.setInterval(100 * 1000 * 60 * 60);
    // 给定位客户端对象设置定位参数
    mLocationClient.setLocationOption(mLocationOption);
    // 关闭缓存机制
    mLocationOption.setLocationCacheEnable(false);
    // 启动定位
    mLocationClient.startLocation();
}
Also used : AMapLocationClient(com.amap.api.location.AMapLocationClient) AMapLocationClientOption(com.amap.api.location.AMapLocationClientOption)

Example 14 with AMapLocationClientOption

use of com.amap.api.location.AMapLocationClientOption in project LivingInCampus by DulCoder.

the class MainActivity method initLocation.

/**
 * 初始化定位
 */
private void initLocation() {
    // 初始化定位
    mLocationClient = new AMapLocationClient(getApplicationContext());
    // 设置定位回调监听
    mLocationClient.setLocationListener(mLocationListener);
    // 初始化AMapLocationClientOption对象
    mLocationOption = new AMapLocationClientOption();
    // 设置定位模式为AMapLocationMode.Battery_Saving,低功耗模式。
    // mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Battery_Saving);
    // 设置退出时是否杀死service
    mLocationOption.setKillProcess(true);
    // 设置是否返回地址信息(默认返回地址信息)
    mLocationOption.setNeedAddress(true);
    // 获取是否单次定位
    mLocationOption.setOnceLocation(true);
    // 给定位客户端对象设置定位参数
    mLocationClient.setLocationOption(mLocationOption);
    // 启动定位
    mLocationClient.startLocation();
}
Also used : AMapLocationClient(com.amap.api.location.AMapLocationClient) AMapLocationClientOption(com.amap.api.location.AMapLocationClientOption)

Example 15 with AMapLocationClientOption

use of com.amap.api.location.AMapLocationClientOption in project CustomViews by AndroidStudy233.

the class CitySelectorActivity method initGaodeLocation.

/**
 * 初始化高德地图定位
 */
private void initGaodeLocation() {
    gaodeClient = new AMapLocationClient(this);
    AMapLocationClientOption option = new AMapLocationClientOption();
    option.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
    // 设置只定位一次
    option.setOnceLocation(true);
    // 设置返回地址信息
    option.setNeedAddress(true);
    // 定位超时
    option.setHttpTimeOut(20000);
    // option.setInterval(20000);// 设置定位间隔,默认为2000ms,最低1000ms。
    gaodeClient.setLocationListener(new AMapLocationListener() {

        @Override
        public void onLocationChanged(AMapLocation aMapLocation) {
            if (aMapLocation != null) {
                if (aMapLocation.getErrorCode() == 0) {
                    String city = aMapLocation.getCity();
                    String district = aMapLocation.getDistrict();
                    mCityAdapter.updateLocateState(LocateState.SUCCESS, city);
                    CLogUtil.d("高德city: " + city);
                    CLogUtil.d("高德district: " + district);
                } else {
                    // 定位失败
                    mCityAdapter.updateLocateState(LocateState.FAILED, null);
                    CLogUtil.e("高德Error, ErrCode:" + aMapLocation.getErrorCode() + ", errInfo:" + aMapLocation.getErrorInfo());
                }
            }
        }
    });
    gaodeClient.setLocationOption(option);
    // gaodeClient.startLocation();
    checkLocationPermission();
}
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)

Aggregations

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