Java Code Examples for com.amap.api.location.AMapLocationClientOption#setWifiActiveScan()

The following examples show how to use com.amap.api.location.AMapLocationClientOption#setWifiActiveScan() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From Ency with Apache License 2.0 6 votes vote down vote up
/**
 * 定位初始化
 */
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();
}
 
Example 2
Source File: SplashPresenter.java    From LittleFreshWeather with Apache License 2.0 6 votes vote down vote up
private void initLocation() {
    mLocationClient = new AMapLocationClient(mView.getContext().getApplicationContext());
    mLocationClientOption = new AMapLocationClientOption();
    //设置定位模式为高精度模式,Battery_Saving为低功耗模式,Device_Sensors是仅设备模式
    mLocationClientOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
    //设置是否返回地址信息(默认返回地址信息)
    mLocationClientOption.setNeedAddress(true);
    //设置是否只定位一次,默认为false
    mLocationClientOption.setOnceLocation(false);
    //设置是否强制刷新WIFI,默认为强制刷新
    mLocationClientOption.setWifiActiveScan(true);
    //设置是否允许模拟位置,默认为false,不允许模拟位置
    mLocationClientOption.setMockEnable(true);
    //设置定位间隔,单位毫秒,默认为2000ms
    mLocationClientOption.setInterval(1000);
    mLocationClient.setLocationOption(mLocationClientOption);
    mLocationClient.setLocationListener(this);
}
 
Example 3
Source File: LocationManager.java    From Android-Application-ZJB with Apache License 2.0 6 votes vote down vote up
public void init() {
    //初始化定位参数
    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);
    //设置定位间隔,单位毫秒,默认为2000ms
    mLocationOption.setInterval(2000);
}
 
Example 4
Source File: FindMapAroundAty.java    From myapplication with Apache License 2.0 6 votes vote down vote up
private void initLoc() {
    //初始化定位
    mLocationClient = new AMapLocationClient(getApplicationContext());
    //设置定位回调监听
    mLocationClient.setLocationListener(this);
    //初始化定位参数
    mLocationOption = new AMapLocationClientOption();
    //设置定位模式为高精度模式,Battery_Saving为低功耗模式,Device_Sensors是仅设备模式
    mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
    //设置是否返回地址信息(默认返回地址信息)
    mLocationOption.setNeedAddress(true);
    //设置是否只定位一次,默认为false
    mLocationOption.setOnceLocation(true);
    //设置是否强制刷新WIFI,默认为强制刷新
    mLocationOption.setWifiActiveScan(true);
    //设置是否允许模拟位置,默认为false,不允许模拟位置
    mLocationOption.setMockEnable(false);
    //设置定位间隔,单位毫秒,默认为2000ms
    mLocationOption.setInterval(2000);
    //给定位客户端对象设置定位参数
    mLocationClient.setLocationOption(mLocationOption);
    //启动定位
    mLocationClient.startLocation();
}
 
Example 5
Source File: MainFragment.java    From SeeWeather with Apache License 2.0 5 votes vote down vote up
/**
 * 高德定位
 */
private void location() {
    //初始化定位
    mLocationClient = new AMapLocationClient(getActivity());
    mLocationOption = new AMapLocationClientOption();
    mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Battery_Saving);
    mLocationOption.setNeedAddress(true);
    mLocationOption.setOnceLocation(true);
    mLocationOption.setWifiActiveScan(false);
    //设置定位间隔 单位毫秒
    int autoUpdateTime = SharedPreferenceUtil.getInstance().getAutoUpdate();
    mLocationOption.setInterval((autoUpdateTime == 0 ? 100 : autoUpdateTime) * SharedPreferenceUtil.ONE_HOUR);
    mLocationClient.setLocationOption(mLocationOption);
    mLocationClient.setLocationListener(aMapLocation -> {
        if (aMapLocation != null) {
            if (aMapLocation.getErrorCode() == 0) {
                aMapLocation.getLocationType();
                SharedPreferenceUtil.getInstance().setCityName(Util.replaceCity(aMapLocation.getCity()));
            } else {
                if (isAdded()) {
                    ToastUtil.showShort(getString(R.string.errorLocation));
                }
            }
            load();
        }
    });
    mLocationClient.startLocation();
}
 
Example 6
Source File: AMapLocationReactModule.java    From react-native-amap-location with MIT License 4 votes vote down vote up
@ReactMethod
public void startLocation(@Nullable ReadableMap options) {
    this.mLocationClient.startLocation();
    AMapLocationClientOption mLocationOption = new AMapLocationClientOption();
    // 默认值
    needMars = false;
    needDetail = false;
    if (options != null) {
        if (options.hasKey("needMars")) {
            needMars = options.getBoolean("needMars");
        }
        if (options.hasKey("needDetail")) {
            needDetail = options.getBoolean("needDetail");
        }
        if (options.hasKey("accuracy")) {
            //设置定位模式为高精度模式,Battery_Saving为低功耗模式,Device_Sensors是仅设备模式
            switch(options.getString("accuracy")) {
                case "BatterySaving":
                    mLocationOption.setLocationMode(AMapLocationMode.Battery_Saving);
                    break;
                case "DeviceSensors":
                    mLocationOption.setLocationMode(AMapLocationMode.Device_Sensors);
                    break;
                case "HighAccuracy":
                    mLocationOption.setLocationMode(AMapLocationMode.Hight_Accuracy);
                    break;
                default:
                    break;
            }
        }
        if (options.hasKey("needAddress")) {
            //设置是否返回地址信息(默认返回地址信息)
            mLocationOption.setNeedAddress(options.getBoolean("needAddress"));
        }
        if (options.hasKey("onceLocation")) {
            //设置是否只定位一次,默认为false
            mLocationOption.setOnceLocation(options.getBoolean("onceLocation"));
        }
        if (options.hasKey("wifiActiveScan")) {
            //设置是否强制刷新WIFI,默认为强制刷新
            //模式为仅设备模式(Device_Sensors)时无效
            mLocationOption.setWifiActiveScan(options.getBoolean("wifiActiveScan"));
        }
        if (options.hasKey("mockEnable")) {
            //设置是否允许模拟位置,默认为false,不允许模拟位置
            //模式为低功耗模式(Battery_Saving)时无效
            mLocationOption.setMockEnable(options.getBoolean("mockEnable"));
        }
        if (options.hasKey("interval")) {
            //设置定位间隔,单位毫秒,默认为2000ms
            mLocationOption.setInterval(options.getInt("interval"));
        }
        if (options.hasKey("killProcess")) {
            //设置退出时是否杀死service
            //默认值:false, 不杀死
            //模式为仅设备模式(Device_Sensors)时无效
            mLocationOption.setKillProcess(options.getBoolean("killProcess"));
        }

        if (options.hasKey("httpTimeOut")) {
            //设置联网超时时间
            //默认值:30000毫秒
            //模式为仅设备模式(Device_Sensors)时无效
            mLocationOption.setHttpTimeOut(options.getInt("httpTimeOut"));
        }
    }

    //给定位客户端对象设置定位参数
    this.mLocationClient.setLocationOption(mLocationOption);
    //启动定位
    this.mLocationClient.startLocation();
}