Search in sources :

Example 6 with AMapLocationClientOption

use of com.amap.api.location.AMapLocationClientOption 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 7 with AMapLocationClientOption

use of com.amap.api.location.AMapLocationClientOption 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 8 with AMapLocationClientOption

use of com.amap.api.location.AMapLocationClientOption in project KL2 by jweihao.

the class GaoDeActivity method getDefaultOption.

/**
 * 默认的定位参数
 */
private AMapLocationClientOption getDefaultOption() {
    AMapLocationClientOption mOption = new AMapLocationClientOption();
    // 可选,设置定位模式,可选的模式有高精度、仅设备、仅网络。默认为高精度模式
    mOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
    // 可选,设置是否gps优先,只在高精度模式下有效。默认关闭
    mOption.setGpsFirst(false);
    // 可选,设置网络请求超时时间。默认为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);
    // 如果您希望位置被模拟,请通过setMockEnable(true);方法开启允许位置模拟
    mOption.setMockEnable(true);
    return mOption;
}
Also used : AMapLocationClientOption(com.amap.api.location.AMapLocationClientOption)

Example 9 with AMapLocationClientOption

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

the class MyCityPresenter method getDefaultOption.

@Override
public AMapLocationClientOption getDefaultOption() {
    AMapLocationClientOption mOption = new AMapLocationClientOption();
    // 可选,设置定位模式,可选的模式有高精度、仅设备、仅网络。默认为高精度模式
    mOption.setLocationMode(AMapLocationMode.Hight_Accuracy);
    // 可选,设置是否gps优先,只在高精度模式下有效。默认关闭
    mOption.setGpsFirst(false);
    // 可选,设置网络请求超时时间。默认为30秒。在仅设备模式下无效
    mOption.setHttpTimeOut(30000);
    // 可选,设置定位间隔。默认为2秒
    mOption.setInterval(5000);
    // 可选,设置是否返回逆地理地址信息。默认是true
    mOption.setNeedAddress(true);
    // 可选,设置是否单次定位。默认是false
    mOption.setOnceLocation(false);
    // 可选,设置是否等待wifi刷新,默认为false.如果设置为true,会自动变为单次定位,持续定位时不要使用
    mOption.setOnceLocationLatest(false);
    // 可选, 设置网络请求的协议。可选HTTP或者HTTPS。默认为HTTP
    AMapLocationClientOption.setLocationProtocol(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 10 with AMapLocationClientOption

use of com.amap.api.location.AMapLocationClientOption in project ride-read-android by Ride-Read.

the class MapFragment method activate.

@Override
public void activate(OnLocationChangedListener onLocationChangedListener) {
    mListener = onLocationChangedListener;
    parentActivity = (MainActivity) getActivity();
    if (parentActivity.mLocationOption == null) {
        // 初始化AMapLocationClientOption对象
        parentActivity.mLocationOption = new AMapLocationClientOption();
    }
    if (aMapLocationClient == null) {
        aMapLocationClient = new AMapLocationClient(getActivity().getApplicationContext());
    }
    setLocationMode(parentActivity.mLocationOption);
    initLocation();
}
Also used : AMapLocationClient(com.amap.api.location.AMapLocationClient) AMapLocationClientOption(com.amap.api.location.AMapLocationClientOption)

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