com.baidu.location.LocationClientOption

Here are the examples of the java api com.baidu.location.LocationClientOption taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

65 Examples 7

19 Source : WeatherService.java
with Apache License 2.0
from Z-bm

private void initLocation() {
    LocationClientOption option = new LocationClientOption();
    option.setLocationMode(LocationClientOption.LocationMode.Battery_Saving);
    // 可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
    option.setCoorType("bd09ll");
    // 可选,默认gcj02,设置返回的定位结果坐标系
    option.setIsNeedAddress(true);
    // 可选,设置是否需要地址信息,默认不需要
    option.setOpenGps(true);
    // 可选,默认false,设置是否使用gps
    option.setLocationNotify(true);
    // 可选,默认false,设置是否当GPS有效时按照1S/1次频率输出GPS结果
    option.setIsNeedLocationDescribe(true);
    // 可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近”
    option.setIsNeedLocationPoiList(true);
    // 可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到
    option.setIgnoreKillProcess(false);
    // 可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死
    option.SetIgnoreCacheException(false);
    // 可选,默认false,设置是否收集CRASH信息,默认收集
    option.setEnableSimulateGps(false);
    // 可选,默认false,设置是否需要过滤GPS仿真结果,默认需要
    mLocationClient.setLocOption(option);
}

19 Source : RouteService.java
with Apache License 2.0
from yiwent

private void initLocation() {
    mIconLocation = BitmapDescriptorFactory.fromResource(R.mipmap.location_marker);
    locationMode = MyLocationConfiguration.LocationMode.NORMAL;
    // 定位服务的客户端。宿主程序在客户端声明此类,并调用,目前只支持在主线程中启动
    mlocationClient = new LocationClient(this);
    mlistener = new MylocationListener();
    // initMarkerClickEvent();
    // 注册监听器
    mlocationClient.registerLocationListener(mlistener);
    // 配置定位SDK各配置参数,比如定位模式、定位时间间隔、坐标系类型等
    LocationClientOption mOption = new LocationClientOption();
    // 设置坐标类型
    mOption.setCoorType("bd09ll");
    // 设置是否需要地址信息,默认为无地址
    mOption.setIsNeedAddress(true);
    // 设置是否打开gps进行定位
    mOption.setOpenGps(true);
    // 设置扫描间隔,单位是毫秒 当<1000(1s)时,定时定位无效
    int span = 10000;
    mOption.setScanSpan(span);
    // 设置 LocationClientOption
    mlocationClient.setLocOption(mOption);
    // 初始化图标,BitmapDescriptorFactory是bitmap 描述信息工厂类.
    mIconLocation = BitmapDescriptorFactory.fromResource(R.mipmap.location_marker);
    myOrientationListener = new MyOrientationListener(this);
    // 通过接口回调来实现实时方向的改变
    myOrientationListener.setOnOrientationListener(new MyOrientationListener.OnOrientationListener() {

        @Override
        public void onOrientationChanged(float x) {
        }
    });
    // mSearch = RoutePlanSearch.newInstance();
    // mSearch.setOnGetRoutePlanResultListener(this);
    // //开启定位
    // mBaiduMap.setMyLocationEnabled(true);
    if (!mlocationClient.isStarted()) {
        mlocationClient.start();
    }
    myOrientationListener.start();
}

19 Source : LocationHelper.java
with Apache License 2.0
from yangjiantao

/**
 * 定位辅助类。
 * 对百度定位的封装。
 *
 * @author Jiantao.Yang
 *         2017/1/10 19:17
 * @version 1.0
 */
public clreplaced LocationHelper {

    final BDLocationService locationService;

    final LocationClientOption option;

    public LocationHelper(Context context) {
        this(new Builder(context));
    }

    private LocationHelper(Builder builder) {
        this.locationService = builder.mLocationService;
        this.option = builder.mOption;
    }

    public boolean registerLocationListener(LocationListener listener) {
        return locationService.registerLocationListener(listener);
    }

    public void unRegisterLocationListener(LocationListener listener) {
        locationService.unRegisterLocationListener(listener);
    }

    public void start() {
        locationService.start();
    }

    public void stop() {
        locationService.stop();
    }

    public static final clreplaced Builder {

        public static final int LOCATION_MODE_HIGH_ACCURACY = 1;

        public static final int LOCATION_MODE_BATTERY_SAVING = 2;

        public static final int LOCATION_MODE_DEVICE_SENSORS = 3;

        LocationClientOption mOption;

        BDLocationService mLocationService;

        @IntDef({ LOCATION_MODE_HIGH_ACCURACY, LOCATION_MODE_BATTERY_SAVING, LOCATION_MODE_DEVICE_SENSORS })
        @Retention(RetentionPolicy.SOURCE)
        public @interface LocateMode {
        }

        public Builder(Context context) {
            this.mLocationService = BDLocationService.getSingleton(context);
            this.mOption = mLocationService.getDefaultLocationClientOption();
        }

        /**
         * //可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
         *
         * @param mode one of {@link #LOCATION_MODE_HIGH_ACCURACY}, {@link #LOCATION_MODE_BATTERY_SAVING} ,or {@link #LOCATION_MODE_DEVICE_SENSORS}
         */
        public Builder setLocationMode(@LocateMode int mode) {
            LocationClientOption.LocationMode bdMode = LocationClientOption.LocationMode.Hight_Accuracy;
            switch(mode) {
                case LOCATION_MODE_BATTERY_SAVING:
                    bdMode = LocationClientOption.LocationMode.Battery_Saving;
                    break;
                case LOCATION_MODE_DEVICE_SENSORS:
                    bdMode = LocationClientOption.LocationMode.Device_Sensors;
                    break;
            }
            mOption.setLocationMode(bdMode);
            return this;
        }

        /**
         * 可选,默认gcj02,设置返回的定位结果坐标系,如果配合百度地图使用,建议设置为bd09ll;
         * @param coorType
         */
        public Builder setCoorType(String coorType) {
            mOption.setCoorType(coorType);
            return this;
        }

        /**
         * 可选,默认0,即仅定位一次,设置发起定位请求的间隔需要大于等于1000ms才是有效的
         * @param milliseconds
         */
        public Builder setScanSpan(int milliseconds) {
            mOption.setScanSpan(milliseconds);
            return this;
        }

        /**
         * 可选,设置是否需要地址信息,默认不需要
         * @param isNeed
         */
        public Builder setIsNeedAddress(boolean isNeed) {
            mOption.setIsNeedAddress(isNeed);
            return this;
        }

        /**
         * 可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近”
         * @param isNeed
         */
        public Builder setIsNeedLocationDescribe(boolean isNeed) {
            mOption.setIsNeedLocationDescribe(isNeed);
            return this;
        }

        /**
         * 可选,默认false,设置定位时是否需要海拔信息,默认不需要,除基础定位版本都可用
         * @param isNeed
         */
        public Builder setIsNeedAlreplacedude(boolean isNeed) {
            mOption.setIsNeedAlreplacedude(isNeed);
            return this;
        }

        /**
         * 可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到
         * @param isNeed
         */
        public Builder setIsNeedLocationPoiList(boolean isNeed) {
            mOption.setIsNeedLocationPoiList(isNeed);
            return this;
        }

        /**
         * 可选,设置是否需要设备方向结果
         * @param isNeed
         */
        public Builder setNeedDeviceDirect(boolean isNeed) {
            mOption.setNeedDeviceDirect(isNeed);
            return this;
        }

        /**
         * 可选,默认false,设置是否当gps有效时按照1S1次频率输出GPS结果
         * @param isNotify
         */
        public Builder setLocationNotify(boolean isNotify) {
            mOption.setLocationNotify(isNotify);
            return this;
        }

        /**
         * 可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死
         * @param isIgnore
         */
        public Builder setIgnoreKillProcess(boolean isIgnore) {
            mOption.setIgnoreKillProcess(isIgnore);
            return this;
        }

        /**
         * 可选,默认false,设置是否收集CRASH信息,默认收集
         * @param isIgnore
         */
        public Builder SetIgnoreCacheException(boolean isIgnore) {
            mOption.SetIgnoreCacheException(isIgnore);
            return this;
        }

        public LocationHelper build() {
            return new LocationHelper(this);
        }
    }

    /**
     * 定位信息
     */
    public static clreplaced LocationEnreplacedy {

        BDLocation bdLocation;

        public LocationEnreplacedy(BDLocation bdLocation) {
            this.bdLocation = bdLocation;
        }

        public String getTime() {
            return this.bdLocation.getTime();
        }

        // 纬度
        public double getLareplacedude() {
            return this.bdLocation.getLareplacedude();
        }

        // 经度
        public double getLongitude() {
            return this.bdLocation.getLongitude();
        }

        public String getCountryCode() {
            return this.bdLocation.getCountryCode();
        }

        public String getCountry() {
            return this.bdLocation.getCountry();
        }

        // 地址信息
        public String getAddrStr() {
            return this.bdLocation.getAddrStr();
        }

        public String getProvince() {
            return this.bdLocation.getProvince();
        }

        public String getCity() {
            return this.bdLocation.getCity();
        }

        public String getCityCode() {
            return this.bdLocation.getCityCode();
        }

        // 区
        public String getDistrict() {
            return this.bdLocation.getDistrict();
        }

        // 街道
        public String getStreet() {
            return this.bdLocation.getStreet();
        }

        public String getStreetNumber() {
            return this.bdLocation.getStreetNumber();
        }

        public String getLocationDescribe() {
            return this.bdLocation.getLocationDescribe();
        }

        // 方向
        public float getDirection() {
            return this.bdLocation.getDirection();
        }

        // GPS定位结果  海拔高度 单位:米
        // 网络定位结果  单位:米
        public double getAlreplacedude() {
            return this.bdLocation.hasAlreplacedude() ? bdLocation.getAlreplacedude() : 0L;
        }

        @Override
        public String toString() {
            if (null != bdLocation && bdLocation.getLocType() != BDLocation.TypeServerError) {
                StringBuffer sb = new StringBuffer(256);
                sb.append("time : ");
                /**
                 * 时间也可以使用systemClock.elapsedRealtime()方法 获取的是自从开机以来,每次回调的时间;
                 * bdLocation.getTime() 是指服务端出本次结果的时间,如果位置不发生变化,则时间不变
                 */
                sb.append(bdLocation.getTime());
                // 定位类型
                sb.append("\nlocType : ");
                sb.append(bdLocation.getLocType());
                // *****对应的定位类型说明*****
                sb.append("\nlocType description : ");
                sb.append(bdLocation.getLocTypeDescription());
                // 纬度
                sb.append("\nlareplacedude : ");
                sb.append(bdLocation.getLareplacedude());
                // 经度
                sb.append("\nlonreplacedude : ");
                sb.append(bdLocation.getLongitude());
                // 半径
                sb.append("\nradius : ");
                sb.append(bdLocation.getRadius());
                // 国家码
                sb.append("\nCountryCode : ");
                sb.append(bdLocation.getCountryCode());
                // 国家名称
                sb.append("\nCountry : ");
                sb.append(bdLocation.getCountry());
                // 城市编码
                sb.append("\ncitycode : ");
                sb.append(bdLocation.getCityCode());
                // 城市
                sb.append("\ncity : ");
                sb.append(bdLocation.getCity());
                // 区
                sb.append("\nDistrict : ");
                sb.append(bdLocation.getDistrict());
                // 街道
                sb.append("\nStreet : ");
                sb.append(bdLocation.getStreet());
                // 地址信息
                sb.append("\naddr : ");
                sb.append(bdLocation.getAddrStr());
                // *****返回用户室内外判断结果*****
                sb.append("\nUserIndoorState: ");
                sb.append(bdLocation.getUserIndoorState());
                sb.append("\nDirection(not all devices have value): ");
                // 方向
                sb.append(bdLocation.getDirection());
                sb.append("\nlocationdescribe: ");
                // 位置语义化信息
                sb.append(bdLocation.getLocationDescribe());
                // POI信息
                sb.append("\nPoi: ");
                if (bdLocation.getPoiList() != null && !bdLocation.getPoiList().isEmpty()) {
                    for (int i = 0; i < bdLocation.getPoiList().size(); i++) {
                        Poi poi = (Poi) bdLocation.getPoiList().get(i);
                        sb.append(poi.getName() + ";");
                    }
                }
                if (bdLocation.getLocType() == BDLocation.TypeGpsLocation) {
                    // GPS定位结果
                    sb.append("\nspeed : ");
                    // 速度 单位:km/h
                    sb.append(bdLocation.getSpeed());
                    sb.append("\nsatellite : ");
                    // 卫星数目
                    sb.append(bdLocation.getSatelliteNumber());
                    sb.append("\nheight : ");
                    // 海拔高度 单位:米
                    sb.append(bdLocation.getAlreplacedude());
                    sb.append("\ngps status : ");
                    // *****gps质量判断*****
                    sb.append(bdLocation.getGpsAccuracyStatus());
                    sb.append("\ndescribe : ");
                    sb.append("gps定位成功");
                } else if (bdLocation.getLocType() == BDLocation.TypeNetWorkLocation) {
                    // 网络定位结果
                    // 运营商信息
                    if (bdLocation.hasAlreplacedude()) {
                        // *****如果有海拔高度*****
                        sb.append("\nheight : ");
                        // 单位:米
                        sb.append(bdLocation.getAlreplacedude());
                    }
                    // 运营商信息
                    sb.append("\noperationers : ");
                    sb.append(bdLocation.getOperators());
                    sb.append("\ndescribe : ");
                    sb.append("网络定位成功");
                } else if (bdLocation.getLocType() == BDLocation.TypeOffLineLocation) {
                    // 离线定位结果
                    sb.append("\ndescribe : ");
                    sb.append("离线定位成功,离线定位结果也是有效的");
                } else if (bdLocation.getLocType() == BDLocation.TypeServerError) {
                    sb.append("\ndescribe : ");
                    sb.append("服务端网络定位失败,可以反馈IMEI号和大体定位时间到[email protected],会有人追查原因");
                } else if (bdLocation.getLocType() == BDLocation.TypeNetWorkException) {
                    sb.append("\ndescribe : ");
                    sb.append("网络不同导致定位失败,请检查网络是否通畅");
                } else if (bdLocation.getLocType() == BDLocation.TypeCriteriaException) {
                    sb.append("\ndescribe : ");
                    sb.append("无法获取有效定位依据导致定位失败,一般是由于手机的原因,处于飞行模式下一般会造成这种结果,可以试着重启手机");
                }
                return sb.toString();
            }
            return "";
        }
    }

    public static abstract clreplaced LocationListener implements BDLocationListener {

        @Override
        public final void onReceiveLocation(BDLocation bdLocation) {
            if (null != bdLocation && bdLocation.getLocType() != BDLocation.TypeServerError) {
                LocationEnreplacedy location = new LocationEnreplacedy(bdLocation);
                onReceiveLocation(location);
                String errorMsg = null;
                if (bdLocation.getLocType() == BDLocation.TypeServerError) {
                    errorMsg = "服务端网络定位失败,可以反馈IMEI号和大体定位时间到[email protected],会有人追查原因";
                } else if (bdLocation.getLocType() == BDLocation.TypeNetWorkException) {
                    errorMsg = "网络不同导致定位失败,请检查网络是否通畅";
                } else if (bdLocation.getLocType() == BDLocation.TypeCriteriaException) {
                    errorMsg = "无法获取有效定位依据导致定位失败,一般是由于手机的原因,处于飞行模式下一般会造成这种结果,可以试着重启手机";
                }
                if (!TextUtils.isEmpty(errorMsg)) {
                    onError(new Throwable(errorMsg));
                }
            } else {
                onError(new Throwable("uncaught exception"));
            }
        }

        public abstract void onReceiveLocation(LocationEnreplacedy location);

        public void onError(Throwable e) {
        }
    }
}

19 Source : BDLocationService.java
with Apache License 2.0
from yangjiantao

/**
 * baidu locate service
 *
 * @author Jiantao.Yang
 *         2017/1/12 14:47
 * @version 1.0
 */
public clreplaced BDLocationService {

    private LocationClient mClient;

    private LocationClientOption mOption;

    private volatile static BDLocationService sInstance;

    private BDLocationService(Context context) {
        mClient = new LocationClient(context);
        mClient.setLocOption(getDefaultLocationClientOption());
    }

    /**
     * @param context  applicationContext
     * @return
     */
    public static BDLocationService getSingleton(Context context) {
        if (sInstance == null) {
            synchronized (BDLocationService.clreplaced) {
                if (sInstance == null) {
                    sInstance = new BDLocationService(context);
                }
            }
        }
        return sInstance;
    }

    public boolean registerLocationListener(BDLocationListener listener) {
        boolean isSuccess = false;
        if (listener != null) {
            mClient.registerLocationListener(listener);
            isSuccess = true;
        }
        return isSuccess;
    }

    public void unRegisterLocationListener(BDLocationListener listener) {
        if (listener != null) {
            mClient.unRegisterLocationListener(listener);
        }
    }

    /**
     * start locate
     */
    public synchronized void start() {
        if (mClient != null && !mClient.isStarted()) {
            mClient.start();
        }
    }

    /**
     * stop locate
     */
    public synchronized void stop() {
        if (mClient != null && mClient.isStarted()) {
            mClient.stop();
        }
    }

    /**
     * @param option
     * @return isSuccessSetOption
     */
    public boolean setLocationOption(LocationClientOption option) {
        boolean isSuccess = false;
        if (option != null) {
            if (mClient.isStarted())
                mClient.stop();
            mOption = option;
            mClient.setLocOption(option);
            isSuccess = true;
        }
        return isSuccess;
    }

    public LocationClientOption getDefaultLocationClientOption() {
        if (mOption == null) {
            mOption = new LocationClientOption();
            // 可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
            mOption.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
            // 可选,默认gcj02,设置返回的定位结果坐标系,如果配合百度地图使用,建议设置为bd09ll;
            mOption.setCoorType("bd09ll");
            // 可选,默认0,即仅定位一次,设置发起定位请求的间隔需要大于等于1000ms才是有效的
            mOption.setScanSpan(0);
            // 可选,设置是否需要地址信息,默认不需要
            mOption.setIsNeedAddress(true);
            // 可选,设置是否需要地址描述
            mOption.setIsNeedLocationDescribe(true);
            // 可选,设置是否需要设备方向结果
            mOption.setNeedDeviceDirect(false);
            // 可选,默认false,设置是否当gps有效时按照1S1次频率输出GPS结果
            mOption.setLocationNotify(false);
            // 可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死
            mOption.setIgnoreKillProcess(true);
            // 可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近”
            mOption.setIsNeedLocationDescribe(false);
            // 可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到
            mOption.setIsNeedLocationPoiList(false);
            // 可选,默认false,设置是否收集CRASH信息,默认收集
            mOption.SetIgnoreCacheException(false);
            // 可选,默认false,设置定位时是否需要海拔信息,默认不需要,除基础定位版本都可用
            mOption.setIsNeedAlreplacedude(false);
        }
        return mOption;
    }
}

19 Source : BDLocationService.java
with Apache License 2.0
from yangjiantao

/**
 * @param option
 * @return isSuccessSetOption
 */
public boolean setLocationOption(LocationClientOption option) {
    boolean isSuccess = false;
    if (option != null) {
        if (mClient.isStarted())
            mClient.stop();
        mOption = option;
        mClient.setLocOption(option);
        isSuccess = true;
    }
    return isSuccess;
}

19 Source : LocationService.java
with Apache License 2.0
from xuexiangjys

/**
 * 设置定位参数
 * @param option
 * @return
 */
public boolean setLocationOption(LocationClientOption option) {
    if (option != null) {
        if (mClient.isStarted()) {
            mClient.stop();
        }
        mDIYOption = option;
        mClient.setLocOption(option);
        return true;
    }
    return false;
}

19 Source : LocationActivity.java
with GNU General Public License v3.0
from xmmmmmovo

// 5秒更新一下位置
private void initLocation() {
    LocationClientOption option = new LocationClientOption();
    option.setScanSpan(5000);
    // //只使用GPS进行定位
    // option.setLocationMode(LocationClientOption.LocationMode.Device_Sensors);
    // 更简单易懂的定位显示
    option.setIsNeedAddress(true);
    mLocationClient.setLocOption(option);
}

19 Source : LocationService.java
with Apache License 2.0
from wangzhijun1124

public clreplaced LocationService {

    private LocationClient client = null;

    private LocationClientOption mOption, DIYoption;

    private Object objLock = new Object();

    public LocationService(Context locationContext) {
        synchronized (objLock) {
            if (client == null) {
                client = new LocationClient(locationContext);
                client.setLocOption(getDefaultLocationClientOption());
            }
        }
    }

    public boolean registerListener(BDAbstractLocationListener listener) {
        boolean isSuccess = false;
        if (listener != null) {
            client.registerLocationListener(listener);
            isSuccess = true;
        }
        return isSuccess;
    }

    public void unregisterListener(BDAbstractLocationListener listener) {
        if (listener != null) {
            client.unRegisterLocationListener(listener);
        }
    }

    public boolean setLocationOption(LocationClientOption option) {
        boolean isSuccess = false;
        if (option != null) {
            if (client.isStarted())
                client.stop();
            DIYoption = option;
            client.setLocOption(option);
        }
        return isSuccess;
    }

    public LocationClientOption getOption() {
        return DIYoption;
    }

    public LocationClientOption getDefaultLocationClientOption() {
        if (mOption == null) {
            mOption = new LocationClientOption();
            // 可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
            mOption.setLocationMode(LocationMode.Hight_Accuracy);
            // 可选,默认gcj02,设置返回的定位结果坐标系,如果配合百度地图使用,建议设置为bd09ll;
            mOption.setCoorType("bd09ll");
            // 可选,默认0,即仅定位一次,设置发起定位请求的间隔需要大于等于1000ms才是有效的
            mOption.setScanSpan(3000);
            // 可选,设置是否需要地址信息,默认不需要
            mOption.setIsNeedAddress(true);
            // 可选,设置是否需要地址描述
            mOption.setIsNeedLocationDescribe(true);
            // 可选,设置是否需要设备方向结果
            mOption.setNeedDeviceDirect(false);
            // 可选,默认false,设置是否当gps有效时按照1S1次频率输出GPS结果
            mOption.setLocationNotify(false);
            // 可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死
            mOption.setIgnoreKillProcess(true);
            // 可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近”
            mOption.setIsNeedLocationDescribe(true);
            // 可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到
            mOption.setIsNeedLocationPoiList(true);
            // 可选,默认false,设置是否收集CRASH信息,默认收集
            mOption.SetIgnoreCacheException(false);
            // 可选,默认false,设置定位时是否需要海拔信息,默认不需要,除基础定位版本都可用
            mOption.setIsNeedAlreplacedude(false);
        }
        return mOption;
    }

    public void start() {
        synchronized (objLock) {
            if (client != null && !client.isStarted()) {
                client.start();
            }
        }
    }

    public void stop() {
        synchronized (objLock) {
            if (client != null && client.isStarted()) {
                client.stop();
            }
        }
    }

    public boolean requestHotSpotState() {
        return client.requestHotSpotState();
    }
}

19 Source : LocationFragment.java
with Apache License 2.0
from Sambor123

private void initLocation() {
    LocationClientOption option = new LocationClientOption();
    option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
    // 可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
    // 可选,默认gcj02,设置返回的定位结果坐标系
    option.setCoorType("bd09ll");
    int span = 2000;
    // 可选,默认0,即仅定位一次,设置发起定位请求的间隔需要大于等于1000ms才是有效的
    option.setScanSpan(0);
    // 可选,设置是否需要地址信息,默认不需要
    option.setIsNeedAddress(true);
    // 可选,默认false,设置是否使用gps
    option.setOpenGps(true);
    // 可选,默认false,设置是否当gps有效时按照1S1次频率输出GPS结果
    option.setLocationNotify(true);
    // 可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近”
    option.setIsNeedLocationDescribe(true);
    // 可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到
    option.setIsNeedLocationPoiList(true);
    // 可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死
    option.setIgnoreKillProcess(false);
    // 可选,默认false,设置是否收集CRASH信息,默认收集
    option.SetIgnoreCacheException(false);
    // 可选,默认false,设置是否需要过滤gps仿真结果,默认需要
    option.setEnableSimulateGps(false);
    mLocationClient.setLocOption(option);
}

19 Source : FakeWeiBoActivity.java
with Apache License 2.0
from REBOOTERS

private void initLocationAndSearch() {
    // location
    // 声明LocationClient类
    mLocationClient = new LocationClient(getApplicationContext());
    // 注册监听函数
    mLocationClient.registerLocationListener(this);
    LocationClientOption option = new LocationClientOption();
    option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
    // 可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
    // 可选,默认gcj02,设置返回的定位结果坐标系
    option.setCoorType("bd09ll");
    int span = 1000;
    // 可选,默认0,即仅定位一次,设置发起定位请求的间隔需要大于等于1000ms才是有效的
    option.setScanSpan(span);
    // 可选,设置是否需要地址信息,默认不需要
    option.setIsNeedAddress(true);
    // 可选,默认false,设置是否使用gps
    option.setOpenGps(true);
    // 可选,默认false,设置是否当GPS有效时按照1S/1次频率输出GPS结果
    option.setLocationNotify(true);
    // 可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近”
    option.setIsNeedLocationDescribe(true);
    // 可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到
    option.setIsNeedLocationPoiList(true);
    // 可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死
    option.setIgnoreKillProcess(false);
    // 可选,默认false,设置是否收集CRASH信息,默认收集
    option.SetIgnoreCacheException(false);
    // 可选,默认false,设置是否需要过滤GPS仿真结果,默认需要
    option.setEnableSimulateGps(false);
    mLocationClient.setLocOption(option);
    // search
    mPoiSearch = PoiSearch.newInstance();
    mPoiSearch.setOnGetPoiSearchResultListener(new MyPoiSearchListener());
    mNearbySearchOption = new PoiNearbySearchOption().radius(5000).pageNum(1).pageCapacity(20).sortType(PoiSortType.distance_from_near_to_far);
    // //////////////
    mGeoCoder = GeoCoder.newInstance();
    mGeoCoder.setOnGetGeoCodeResultListener(new OnGetGeoCoderResultListener() {

        @Override
        public void onGetGeoCodeResult(GeoCodeResult geoCodeResult) {
            Log.e(TAG, "onGetGeoCodeResult: " + geoCodeResult.toString());
        }

        @Override
        public void onGetReverseGeoCodeResult(ReverseGeoCodeResult reverseGeoCodeResult) {
            Log.e(TAG, "onGetReverseGeoCodeResult: " + reverseGeoCodeResult.toString());
        }
    });
}

19 Source : MainActivity.java
with Apache License 2.0
from RealMoMo

private void initLocation() {
    LocationClientOption option = new LocationClientOption();
    option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
    // 可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
    // 可选,默认gcj02,设置返回的定位结果坐标系
    option.setCoorType("bd09ll");
    int span = 1000;
    // 可选,默认0,即仅定位一次,设置发起定位请求的间隔需要大于等于1000ms才是有效的
    option.setScanSpan(span);
    // 可选,设置是否需要地址信息,默认不需要
    option.setIsNeedAddress(true);
    // 可选,默认false,设置是否使用gps
    option.setOpenGps(true);
    // 可选,默认false,设置是否当GPS有效时按照1S/1次频率输出GPS结果
    option.setLocationNotify(true);
    // 可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近”
    option.setIsNeedLocationDescribe(true);
    // 可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到
    option.setIsNeedLocationPoiList(true);
    // 可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死
    option.setIgnoreKillProcess(false);
    // 可选,默认false,设置是否收集CRASH信息,默认收集
    option.SetIgnoreCacheException(false);
    // 可选,默认false,设置是否需要过滤GPS仿真结果,默认需要
    option.setEnableSimulateGps(false);
    mLocationClient.setLocOption(option);
}

19 Source : MapActivity.java
with Apache License 2.0
from NorwegianForest

private void initLocation() {
    LocationClientOption option = new LocationClientOption();
    option.setScanSpan(5000);
    option.setIsNeedAddress(true);
    mLocationClient.setLocOption(option);
}

19 Source : LocationUtil.java
with MIT License
from maxiaozhou1234

private LocationClientOption getOption() {
    LocationClientOption option = new LocationClientOption();
    option.setIsNeedAddress(true);
    option.setCoorType("bd09ll");
    option.setLocationMode(LocationClientOption.LocationMode.Battery_Saving);
    // option.setScanSpan(1000);
    option.setLocationNotify(false);
    return option;
}

19 Source : BaiduLocation.java
with Apache License 2.0
from LuoPeiQin

/**
 * Created by 44607 on 2017/4/25.
 */
public clreplaced BaiduLocation {

    private LocationClient client = null;

    private LocationClientOption mOption, DIYoption;

    private Object objLock = new Object();

    /**
     * @param locationContext
     */
    public BaiduLocation(Context locationContext) {
        synchronized (objLock) {
            if (client == null) {
                client = new LocationClient(locationContext);
                client.setLocOption(getDefaultLocationClientOption());
            }
        }
    }

    /**
     * @param listener
     * @return
     */
    public boolean registerListener(BDLocationListener listener) {
        boolean isSuccess = false;
        if (listener != null) {
            client.registerLocationListener(listener);
            isSuccess = true;
        }
        return isSuccess;
    }

    public void unregisterListener(BDLocationListener listener) {
        if (listener != null) {
            client.unRegisterLocationListener(listener);
        }
    }

    /**
     * @param option
     * @return isSuccessSetOption
     */
    public boolean setLocationOption(LocationClientOption option) {
        boolean isSuccess = false;
        if (option != null) {
            if (client.isStarted())
                client.stop();
            DIYoption = option;
            client.setLocOption(option);
        }
        return isSuccess;
    }

    public LocationClientOption getOption() {
        return DIYoption;
    }

    /**
     * @return DefaultLocationClientOption
     */
    public LocationClientOption getDefaultLocationClientOption() {
        if (mOption == null) {
            mOption = new LocationClientOption();
            // 可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
            mOption.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
            // mOption.setCoorType("bd09ll");//可选,默认gcj02,设置返回的定位结果坐标系,如果配合百度地图使用,建议设置为bd09ll;
            // 可选,默认0,即仅定位一次,设置发起定位请求的间隔需要大于等于1000ms才是有效的
            mOption.setScanSpan(60 * 60 * 1000);
        // mOption.setIsNeedAddress(true);//可选,设置是否需要地址信息,默认不需要
        // mOption.setIsNeedLocationDescribe(true);//可选,设置是否需要地址描述
        // mOption.setNeedDeviceDirect(false);//可选,设置是否需要设备方向结果
        // mOption.setLocationNotify(false);//可选,默认false,设置是否当gps有效时按照1S1次频率输出GPS结果
        // mOption.setIgnoreKillProcess(true);//可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死
        // mOption.setIsNeedLocationDescribe(true);//可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近”
        // mOption.setIsNeedLocationPoiList(true);//可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到
        // mOption.SetIgnoreCacheException(false);//可选,默认false,设置是否收集CRASH信息,默认收集
        // 
        // mOption.setIsNeedAlreplacedude(false);//可选,默认false,设置定位时是否需要海拔信息,默认不需要,除基础定位版本都可用
        }
        return mOption;
    }

    public void start() {
        synchronized (objLock) {
            if (client != null && !client.isStarted()) {
                client.start();
            }
        }
    }

    public void stop() {
        synchronized (objLock) {
            if (client != null && client.isStarted()) {
                client.stop();
            }
        }
    }

    public boolean requestHotSpotState() {
        return client.requestHotSpotState();
    }
    // public static final int BAIDU_LOCATION_EVENT = 1;
    // private final static boolean DEBUG = true;
    // private final static String TAG = "BaiduLocation";
    // private static BaiduLocation mInstance;
    // private BDLocation mLocation = null;
    // public CurrentLocation  currentLocation = new CurrentLocation();
    // public BDLocationListener myListener = new MyLocationListener();
    // private LocationClient mLocationClient;
    // 
    // public static BaiduLocation getInstance(Context context) {
    // if (mInstance == null) {
    // mInstance = new BaiduLocation(context);
    // }
    // return mInstance;
    // }
    // 
    // private BaiduLocation(Context context) {
    // mLocationClient = new LocationClient(context);
    // initParams();
    // mLocationClient.registerLocationListener(myListener);
    // startMonitor();
    // }
    // 
    // public void startMonitor() {
    // if (DEBUG) Log.d(TAG, "start monitor location");
    // if (!mLocationClient.isStarted()) {
    // mLocationClient.start();
    // }
    // while (mLocationClient != null && mLocationClient.isStarted()) {
    // mLocationClient.requestLocation();
    // }
    // //        else {
    // //            Log.d("LocSDK3", "locClient is null or not started");
    // //        }
    // }
    // 
    // public void stopMonitor() {
    // if (DEBUG) Log.d(TAG, "stop monitor location");
    // if (mLocationClient != null && mLocationClient.isStarted()) {
    // mLocationClient.stop();
    // }
    // }
    // 
    // public BDLocation getLocation() {
    // if (DEBUG) Log.d(TAG, "get location");
    // return mLocation;
    // }
    // 
    // public CurrentLocation getBaseLocation() {
    // if (DEBUG) Log.d(TAG, "get location");
    // return currentLocation;
    // }
    // 
    // private void initParams() {
    // LocationClientOption option = new LocationClientOption();
    // option.setOpenGps(true);
    // option.setPriority(LocationClientOption.NetWorkFirst);
    // option.setCoorType("bd09ll");//返回的定位结果是百度经纬度,默认值gcj02
    // option.setScanSpan(60*60*1000);//设置发起定位请求的间隔时间为5000ms
    // option.disableCache(false);//禁止启用缓存定位
    // mLocationClient.setLocOption(option);
    // }
    // 
    // 
    // public clreplaced MyLocationListener implements BDLocationListener {
    // @Override
    // public void onReceiveLocation(BDLocation location) {
    // if (location == null) {
    // return ;
    // }
    // mLocation = location;
    // currentLocation.lareplacedude = mLocation.getLareplacedude();
    // currentLocation.longitude = mLocation.getLongitude();
    // String tempString1 = String.valueOf(currentLocation.lareplacedude);
    // String tempString2 = String.valueOf(currentLocation.longitude);
    // //        returnData = tempString1.substring(0,tempString1.indexOf('.') + 4)
    // //        + "," + tempString2.substring(0, tempString2.indexOf('.') + 4);
    // currentLocation.weatherId = tempString2.substring(0,tempString2.indexOf('.') + 4)
    // + "," + tempString1.substring(0, tempString1.indexOf('.') + 4);
    // //            Message message = new Message();
    // //            message.what = BAIDU_LOCATION_EVENT;
    // //            WeatherActivity.handler.sendMessage(message);
    // //            WeatherActivity.isBDLocationOk = true;
    // 
    // Log.d(TAG, "retrunData :" + currentLocation.weatherId);
    // 
    // StringBuffer sb = new StringBuffer(256);
    // sb.append("time : ");
    // sb.append(location.getTime());
    // sb.append("\nerror code : ");
    // sb.append(location.getLocType());
    // sb.append("\nlareplacedude : ");
    // sb.append(location.getLareplacedude());
    // sb.append("\nlonreplacedude : ");
    // sb.append(location.getLongitude());
    // sb.append("\nradius : ");
    // sb.append(location.getRadius());
    // sb.append("\ncity : ");
    // sb.append(location.getCity());
    // if (location.getLocType() == BDLocation.TypeGpsLocation){
    // sb.append("\nspeed : ");
    // sb.append(location.getSpeed());
    // sb.append("\nsatellite : ");
    // sb.append(location.getSatelliteNumber());
    // } else if (location.getLocType() == BDLocation.TypeNetWorkLocation){
    // sb.append("\naddr : ");
    // sb.append(location.getAddrStr());
    // }
    // if (DEBUG) Log.d(TAG, "" + sb);
    // //只需要定位一次就可以了
    // closeLocationClient();
    // }
    // 
    // @Override
    // public void onConnectHotSpotMessage(String s, int i) {
    // 
    // }
    // 
    // }
    // 
    // public clreplaced CurrentLocation {
    // public double lareplacedude;
    // public double longitude;
    // public String weatherId;
    // }
    // 
    // public void closeLocationClient()
    // {
    // mLocationClient.stop();
    // mLocationClient.unRegisterLocationListener(myListener);
    // mLocationClient = null;
    // myListener = null;
    // }
}

19 Source : WelcomeActivity.java
with Apache License 2.0
from HuTianQi

private void initBaiduMapLocation() {
    mLocationClient = new LocationClient(this.getApplicationContext());
    mListener = new MyLocationListener();
    // 娉ㄥ唽鐩戝惉鍑芥暟
    mLocationClient.registerLocationListener(mListener);
    LocationClientOption option = new LocationClientOption();
    option.setLocationMode(LocationMode.Hight_Accuracy);
    option.setIsNeedAddress(true);
    mLocationClient.setLocOption(option);
    mLocationClient.start();
}

19 Source : MainActivity.java
with MIT License
from hornhuang

/**
 * 获得用户个人定位
 */
private void initLocationOption() {
    // 定位服务的客户端。宿主程序在客户端声明此类,并调用,目前只支持在主线程中启动
    locationClient = new LocationClient(getApplicationContext());
    // 声明LocationClient类实例并配置定位参数
    MyLocationListener myLocationListener = new MyLocationListener(locationSetter, mBaiduMap, locationClient);
    // 注册监听函数
    locationClient.registerLocationListener(myLocationListener);
    LocationClientOption locationOption = new LocationClientOption();
    // 可选,默认gcj02,设置返回的定位结果坐标系,如果配合百度地图使用,建议设置为bd09ll;
    locationOption.setCoorType("bd09ll");
    locationOption.setOpenGps(true);
    locationOption.setLocationNotify(true);
    locationClient.setLocOption(locationOption);
    // 开始定位
    locationClient.start();
}

19 Source : LocationService.java
with GNU General Public License v3.0
from Hilaver

/**
 * @author baidu
 */
public clreplaced LocationService {

    private LocationClient client = null;

    private LocationClientOption mOption, DIYoption;

    private Object objLock = new Object();

    /**
     * @param locationContext
     */
    public LocationService(Context locationContext) {
        synchronized (objLock) {
            if (client == null) {
                client = new LocationClient(locationContext);
                client.setLocOption(getDefaultLocationClientOption());
            }
        }
    }

    /**
     * @param listener
     * @return
     */
    public boolean registerListener(BDAbstractLocationListener listener) {
        boolean isSuccess = false;
        if (listener != null) {
            client.registerLocationListener(listener);
            isSuccess = true;
        }
        return isSuccess;
    }

    public void unregisterListener(BDAbstractLocationListener listener) {
        if (listener != null) {
            client.unRegisterLocationListener(listener);
        }
    }

    /**
     * @param option
     * @return isSuccessSetOption
     */
    public boolean setLocationOption(LocationClientOption option) {
        boolean isSuccess = false;
        if (option != null) {
            if (client.isStarted())
                client.stop();
            DIYoption = option;
            client.setLocOption(option);
        }
        return isSuccess;
    }

    /**
     * @return DefaultLocationClientOption  默认O设置
     */
    public LocationClientOption getDefaultLocationClientOption() {
        if (mOption == null) {
            mOption = new LocationClientOption();
            // 可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
            mOption.setLocationMode(LocationMode.Hight_Accuracy);
            // 可选,默认gcj02,设置返回的定位结果坐标系,如果配合百度地图使用,建议设置为bd09ll;
            mOption.setCoorType("bd09ll");
            // 可选,默认0,即仅定位一次,设置发起连续定位请求的间隔需要大于等于1000ms才是有效的
            mOption.setScanSpan(3000);
            // 可选,设置是否需要地址信息,默认不需要
            mOption.setIsNeedAddress(true);
            // 可选,设置是否需要地址描述
            mOption.setIsNeedLocationDescribe(true);
            // 可选,设置是否需要设备方向结果
            mOption.setNeedDeviceDirect(false);
            // 可选,默认false,设置是否当gps有效时按照1S1次频率输出GPS结果
            mOption.setLocationNotify(false);
            // 可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死
            mOption.setIgnoreKillProcess(true);
            // 可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近”
            mOption.setIsNeedLocationDescribe(true);
            // 可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到
            mOption.setIsNeedLocationPoiList(true);
            // 可选,默认false,设置是否收集CRASH信息,默认收集
            mOption.SetIgnoreCacheException(false);
            // 可选,默认false,设置是否开启Gps定位
            mOption.setOpenGps(true);
            // 可选,默认false,设置定位时是否需要海拔信息,默认不需要,除基础定位版本都可用
            mOption.setIsNeedAlreplacedude(false);
        }
        return mOption;
    }

    /**
     * @return DIYOption 自定义Option设置
     */
    public LocationClientOption getOption() {
        if (DIYoption == null) {
            DIYoption = new LocationClientOption();
        }
        return DIYoption;
    }

    public void start() {
        synchronized (objLock) {
            if (client != null && !client.isStarted()) {
                client.start();
            }
        }
    }

    public void stop() {
        synchronized (objLock) {
            if (client != null && client.isStarted()) {
                client.stop();
            }
        }
    }

    public boolean isStart() {
        return client.isStarted();
    }

    public boolean requestHotSpotState() {
        return client.requestHotSpotState();
    }
}

19 Source : ClientOptionFactory.java
with Apache License 2.0
from dudu90

/**
 * 创建百度ClientOption的工厂方法
 *
 * @param option 百度ClientOption 详情请查看{ http://wiki.lbsyun.baidu.com/cms/androidloc/doc/v7.1/index.html }
 * @return ClientOption
 */
public ClientOption createBaiduOption(final LocationClientOption option) {
    return new ClientOption(option);
}

19 Source : TrackerService.java
with Apache License 2.0
from dreamfish797

/**
 * 设置定位参数
 * @param option
 */
public void setLocationOption(LocationClientOption option) {
    if (option != null) {
        if (client.isStarted()) {
            client.stop();
        }
        client.setLocOption(option);
    }
}

19 Source : HooweLocationTracker.java
with Apache License 2.0
from dreamfish797

/**
 * @return DefaultLocationClientOption
 */
public LocationClientOption getDefaultLocationClientOption() {
    LocationClientOption mOption = new LocationClientOption();
    mOption = new LocationClientOption();
    // 可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
    mOption.setLocationMode(LocationMode.Hight_Accuracy);
    // 可选,默认gcj02,设置返回的定位结果坐标系,如果配合百度地图使用,建议设置为bd09ll;
    mOption.setCoorType("bd09ll");
    // 可选,默认0,即仅定位一次,设置发起定位请求的间隔需要大于等于1000ms才是有效的
    mOption.setScanSpan(3000);
    // 可选,设置是否需要地址信息,默认不需要
    mOption.setIsNeedAddress(true);
    // 可选,设置是否需要设备方向结果
    mOption.setNeedDeviceDirect(true);
    // 可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近”
    mOption.setIsNeedLocationDescribe(true);
    // 可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到
    mOption.setIsNeedLocationPoiList(true);
    // 可选,默认false,设置定位时是否需要海拔信息,默认不需要,除基础定位版本都可用
    mOption.setIsNeedAlreplacedude(true);
    return mOption;
}

19 Source : HooweLocationTracker.java
with Apache License 2.0
from dreamfish797

/**
 * @param option
 */
public void setLocationOption(LocationClientOption option) {
    if (option != null) {
        if (client.isStarted())
            client.stop();
        client.setLocOption(option);
    }
}

19 Source : HooweLocationProvider.java
with Apache License 2.0
from dreamfish797

/**
 * 开始位置追踪
 *
 * @param mOption   定位配置
 * @param listener
 */
public void startTracker(LocationClientOption mOption, OnLocationUpdatedListener listener) {
    if (!hasTracker) {
        mTracker = new HooweLocationTracker(mContext);
        mTracker.setLocationOption(mOption);
        mTracker.registerListener(listener);
        mTracker.start();
        hasTracker = true;
    } else {
        // 已经存在追踪任务
        // TODO: 2017/8/28 回调通知调用者
        if (listener != null) {
            listener.onLocationTrackerExist();
        }
    }
}

19 Source : HooweLocationProvider.java
with Apache License 2.0
from dreamfish797

/**
 * 获取当前位置(实时定位)
 *
 * @param mOption
 * @param listener
 */
public void getCurrentLocation(LocationClientOption mOption, OnLocationUpdatedListener listener) {
    if (hasTracker) {
        // 有追踪任务在运行
        // 获取最新位置返回
        HooweLocation location = LocationDBHelper.getHelper(mContext).getLatestLocation();
        listener.onReceiveLocation(location);
    } else {
        HooweLocationTracker locationTracker = new HooweLocationTracker(mContext);
        if (mOption != null) {
            locationTracker.setLocationOption(mOption);
        } else {
            locationTracker.setLocationOption(locationTracker.getDefaultLocationClientOption());
        }
        locationTracker.registerListener(listener);
        locationTracker.start();
    }
}

19 Source : LocationService.java
with GNU General Public License v2.0
from CrazyRunning

/**
 * @author baidu
 */
public clreplaced LocationService {

    private LocationClient client = null;

    private LocationClientOption mOption, DIYoption;

    private Object objLock = new Object();

    /**
     * @param locationContext
     */
    public LocationService(Context locationContext) {
        synchronized (objLock) {
            if (client == null) {
                client = new LocationClient(locationContext);
                client.setLocOption(getDefaultLocationClientOption());
            }
        }
    }

    /**
     * @param listener
     * @return
     */
    public boolean registerListener(BDLocationListener listener) {
        boolean isSuccess = false;
        if (listener != null) {
            client.registerLocationListener(listener);
            isSuccess = true;
        }
        return isSuccess;
    }

    public void unregisterListener(BDLocationListener listener) {
        if (listener != null) {
            client.unRegisterLocationListener(listener);
        }
    }

    /**
     * @param option
     * @return isSuccessSetOption
     */
    public boolean setLocationOption(LocationClientOption option) {
        boolean isSuccess = false;
        if (option != null) {
            if (client.isStarted())
                client.stop();
            DIYoption = option;
            client.setLocOption(option);
        }
        return isSuccess;
    }

    public LocationClientOption getOption() {
        return DIYoption;
    }

    /**
     * @return DefaultLocationClientOption
     */
    public LocationClientOption getDefaultLocationClientOption() {
        if (mOption == null) {
            mOption = new LocationClientOption();
            // 可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
            mOption.setLocationMode(LocationMode.Hight_Accuracy);
            // 可选,默认gcj02,设置返回的定位结果坐标系,如果配合百度地图使用,建议设置为bd09ll;
            mOption.setCoorType("bd09ll");
            // 可选,默认0,即仅定位一次,设置发起定位请求的间隔需要大于等于1000ms才是有效的
            mOption.setScanSpan(3000);
            // 可选,设置是否需要地址信息,默认不需要
            mOption.setIsNeedAddress(true);
            // 可选,设置是否需要地址描述
            mOption.setIsNeedLocationDescribe(true);
            // 可选,设置是否需要设备方向结果
            mOption.setNeedDeviceDirect(false);
            // 可选,默认false,设置是否当gps有效时按照1S1次频率输出GPS结果
            mOption.setLocationNotify(false);
            // 可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死
            mOption.setIgnoreKillProcess(true);
            // 可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近”
            mOption.setIsNeedLocationDescribe(true);
            // 可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到
            mOption.setIsNeedLocationPoiList(true);
            // 可选,默认false,设置是否收集CRASH信息,默认收集
            mOption.SetIgnoreCacheException(false);
        }
        return mOption;
    }

    public void start() {
        synchronized (objLock) {
            if (client != null && !client.isStarted()) {
                client.start();
            }
        }
    }

    public void stop() {
        synchronized (objLock) {
            if (client != null && client.isStarted()) {
                client.stop();
            }
        }
    }
}

19 Source : HomePresenter.java
with MIT License
from byhieg

private void initLocation() {
    LocationClientOption option = new LocationClientOption();
    // 可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
    option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
    // 可选,默认gcj02,设置返回的定位结果坐标系
    option.setCoorType("bd09ll");
    // 可选,默认0,即仅定位一次,设置发起定位请求的间隔需要大于等于1000ms才是有效的
    option.setScanSpan(1000);
    // 可选,设置是否需要地址信息,默认不需要
    option.setIsNeedAddress(true);
    // 可选,默认false,设置是否使用gps
    option.setOpenGps(true);
    // 可选,默认false,设置是否当GPS有效时按照1S/1次频率输出GPS结果
    option.setLocationNotify(true);
    // 可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近”
    option.setIsNeedLocationDescribe(true);
    // 可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到
    option.setIsNeedLocationPoiList(true);
    // 可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死
    option.setIgnoreKillProcess(false);
    // 可选,默认false,设置是否收集CRASH信息,默认收集
    option.SetIgnoreCacheException(false);
    // 可选,默认false,设置是否需要过滤GPS仿真结果,默认需要
    option.setEnableSimulateGps(false);
    MyApplication.getmLocationClient().setLocOption(option);
}

19 Source : LocationUtil.java
with Apache License 2.0
from ApolloAuto

private LocationClientOption initLocationOption() {
    LocationClientOption option = new LocationClientOption();
    // optional,default is high accuracy. low power ,only on the device
    option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
    // optional,default is gcj02,later can return converted coordinate system type
    option.setCoorType("gcj02");
    // optional,default is 0,only location once,
    // it is work when inteval time between location request is greater than or equal to 1000ms
    option.setScanSpan(SPAN_MIL);
    // optional,default is false
    option.setIsNeedAddress(false);
    // optional,default is false,whether use gps
    option.setOpenGps(true);
    // optional,default is false,whether output GPS results acording to 1S1 frequency when gps is valid
    option.setLocationNotify(false);
    // optional,default is false,whether need the describe of the location
    option.setIsNeedLocationDescribe(false);
    // optional,default is false,whether need POI result which can get in BDLocation.getPoiList
    option.setIsNeedLocationPoiList(false);
    // optional,default is true,there is a service in the loaction sdk,
    // and it run in a independent process, whether kill the service when stop
    option.setIgnoreKillProcess(true);
    // optional,default is false,whether collect crash info
    option.SetIgnoreCacheException(false);
    // optional,default is false,weather filter the result of the gps simulation
    option.setEnableSimulateGps(true);
    return option;
}

18 Source : LocationService.java
with Apache License 2.0
from xuexiangjys

/**
 * 定位服务
 *
 * @author xuexiang
 * @since 2019/3/31 下午5:52
 */
public clreplaced LocationService {

    private static volatile LocationService sInstance = null;

    private LocationClient mClient = null;

    private LocationClientOption mOption, mDIYOption;

    private LocatedCity mLocatedCity = null;

    private LocationService() {
    }

    /**
     * 初始化
     * @param context
     */
    public void init(Context context) {
        if (mClient == null) {
            mClient = new LocationClient(context.getApplicationContext());
            mClient.setLocOption(getDefaultLocationClientOption());
        }
    }

    /**
     * 获取单例
     *
     * @return
     */
    public static LocationService get() {
        if (sInstance == null) {
            synchronized (LocationService.clreplaced) {
                if (sInstance == null) {
                    sInstance = new LocationService();
                }
            }
        }
        return sInstance;
    }

    /**
     * 注册定位监听
     * @param listener
     * @return
     */
    public LocationService registerListener(BDAbstractLocationListener listener) {
        if (listener != null) {
            mClient.registerLocationListener(listener);
        }
        return this;
    }

    /**
     * 注销定位监听
     *
     * @param listener
     */
    public LocationService unregisterListener(BDAbstractLocationListener listener) {
        if (listener != null) {
            mClient.unRegisterLocationListener(listener);
        }
        return this;
    }

    /**
     * 设置定位参数
     * @param option
     * @return
     */
    public boolean setLocationOption(LocationClientOption option) {
        if (option != null) {
            if (mClient.isStarted()) {
                mClient.stop();
            }
            mDIYOption = option;
            mClient.setLocOption(option);
            return true;
        }
        return false;
    }

    /**
     * @return DefaultLocationClientOption  默认O设置
     */
    public LocationClientOption getDefaultLocationClientOption() {
        if (mOption == null) {
            mOption = new LocationClientOption();
            // 可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
            mOption.setLocationMode(LocationMode.Hight_Accuracy);
            // 可选,默认gcj02,设置返回的定位结果坐标系,如果配合百度地图使用,建议设置为bd09ll;
            mOption.setCoorType("bd09ll");
            // 可选,默认0,即仅定位一次,设置发起连续定位请求的间隔需要大于等于1000ms才是有效的
            mOption.setScanSpan(0);
            // 可选,设置是否需要地址信息,默认不需要
            mOption.setIsNeedAddress(true);
            // 可选,设置是否需要地址描述
            mOption.setIsNeedLocationDescribe(true);
            // 可选,设置是否需要设备方向结果
            mOption.setNeedDeviceDirect(false);
            // 可选,默认false,设置是否当gps有效时按照1S1次频率输出GPS结果
            mOption.setLocationNotify(false);
            // 可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死
            mOption.setIgnoreKillProcess(true);
            // 可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近”
            mOption.setIsNeedLocationDescribe(true);
            // 可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到
            mOption.setIsNeedLocationPoiList(true);
            // 可选,默认false,设置是否收集CRASH信息,默认收集
            mOption.SetIgnoreCacheException(false);
            // 可选,默认false,设置是否开启Gps定位
            mOption.setOpenGps(true);
            // 可选,默认false,设置定位时是否需要海拔信息,默认不需要,除基础定位版本都可用
            mOption.setIsNeedAlreplacedude(false);
        }
        return mOption;
    }

    /**
     * @return DIYOption 自定义Option设置
     */
    public LocationClientOption getOption() {
        if (mDIYOption == null) {
            mDIYOption = new LocationClientOption();
        }
        return mDIYOption;
    }

    /**
     * 开始定位
     *
     * @param listener
     */
    @Permission(LOCATION)
    public static void start(BDAbstractLocationListener listener) {
        get().registerListener(listener).start();
    }

    /**
     * 开始定位
     */
    public LocationService start() {
        if (mClient != null && !mClient.isStarted()) {
            mClient.start();
        }
        return this;
    }

    /**
     * 停止定位
     */
    public static void stop(BDAbstractLocationListener listener) {
        get().unregisterListener(listener).stop();
    }

    /**
     * 停止定位
     */
    public LocationService stop() {
        if (mClient != null && mClient.isStarted()) {
            mClient.stop();
        }
        return this;
    }

    public boolean isStart() {
        return mClient.isStarted();
    }

    public boolean requestHotSpotState() {
        return mClient.requestHotSpotState();
    }

    /**
     * 当收到定位信息
     *
     * @param bdLocation
     * @return
     */
    public static LocatedCity onReceiveLocation(BDLocation bdLocation) {
        if (get().mLocatedCity == null || bdLocation.getCity() != null) {
            get().mLocatedCity = new LocatedCity(bdLocation.getCity(), bdLocation.getProvince(), bdLocation.getCityCode());
        }
        return get().mLocatedCity;
    }

    public LocationService setLocatedCity(LocatedCity locatedCity) {
        mLocatedCity = locatedCity;
        return this;
    }

    public LocatedCity getLocatedCity() {
        return mLocatedCity;
    }

    /**
     * 打印地址信息
     *
     * @param location
     */
    public static void printLocationInfo(BDLocation location) {
        if (null != location && location.getLocType() != BDLocation.TypeServerError) {
            StringBuilder sb = new StringBuilder(256);
            sb.append("time : ");
            /**
             * 时间也可以使用systemClock.elapsedRealtime()方法 获取的是自从开机以来,每次回调的时间;
             * location.getTime() 是指服务端出本次结果的时间,如果位置不发生变化,则时间不变
             */
            sb.append(location.getTime());
            // 定位类型
            sb.append("\nlocType : ");
            sb.append(location.getLocType());
            // *****对应的定位类型说明*****
            sb.append("\nlocType description : ");
            sb.append(location.getLocTypeDescription());
            // 纬度
            sb.append("\nlareplacedude : ");
            sb.append(location.getLareplacedude());
            // 经度
            sb.append("\nlonreplacedude : ");
            sb.append(location.getLongitude());
            // 半径
            sb.append("\nradius : ");
            sb.append(location.getRadius());
            // 国家码
            sb.append("\nCountryCode : ");
            sb.append(location.getCountryCode());
            // 国家名称
            sb.append("\nCountry : ");
            sb.append(location.getCountry());
            // 城市编码
            sb.append("\ncitycode : ");
            sb.append(location.getCityCode());
            // 城市
            sb.append("\ncity : ");
            sb.append(location.getCity());
            // 区
            sb.append("\nDistrict : ");
            sb.append(location.getDistrict());
            // 街道
            sb.append("\nStreet : ");
            sb.append(location.getStreet());
            // 地址信息
            sb.append("\naddr : ");
            sb.append(location.getAddrStr());
            // *****返回用户室内外判断结果*****
            sb.append("\nUserIndoorState: ");
            sb.append(location.getUserIndoorState());
            sb.append("\nDirection(not all devices have value): ");
            // 方向
            sb.append(location.getDirection());
            sb.append("\nlocationdescribe: ");
            // 位置语义化信息
            sb.append(location.getLocationDescribe());
            // POI信息
            sb.append("\nPoi: ");
            if (location.getPoiList() != null && !location.getPoiList().isEmpty()) {
                for (int i = 0; i < location.getPoiList().size(); i++) {
                    Poi poi = location.getPoiList().get(i);
                    sb.append(poi.getName() + ";");
                }
            }
            if (location.getLocType() == BDLocation.TypeGpsLocation) {
                // GPS定位结果
                sb.append("\nspeed : ");
                // 速度 单位:km/h
                sb.append(location.getSpeed());
                sb.append("\nsatellite : ");
                // 卫星数目
                sb.append(location.getSatelliteNumber());
                sb.append("\nheight : ");
                // 海拔高度 单位:米
                sb.append(location.getAlreplacedude());
                sb.append("\ngps status : ");
                // *****gps质量判断*****
                sb.append(location.getGpsAccuracyStatus());
                sb.append("\ndescribe : ");
                sb.append("gps定位成功");
            } else if (location.getLocType() == BDLocation.TypeNetWorkLocation) {
                // 网络定位结果
                // 运营商信息
                if (location.hasAlreplacedude()) {
                    // *****如果有海拔高度*****
                    sb.append("\nheight : ");
                    // 单位:米
                    sb.append(location.getAlreplacedude());
                }
                // 运营商信息
                sb.append("\noperationers : ");
                sb.append(location.getOperators());
                sb.append("\ndescribe : ");
                sb.append("网络定位成功");
            } else if (location.getLocType() == BDLocation.TypeOffLineLocation) {
                // 离线定位结果
                sb.append("\ndescribe : ");
                sb.append("离线定位成功,离线定位结果也是有效的");
            } else if (location.getLocType() == BDLocation.TypeServerError) {
                sb.append("\ndescribe : ");
                sb.append("服务端网络定位失败,可以反馈IMEI号和大体定位时间到[email protected],会有人追查原因");
            } else if (location.getLocType() == BDLocation.TypeNetWorkException) {
                sb.append("\ndescribe : ");
                sb.append("网络不同导致定位失败,请检查网络是否通畅");
            } else if (location.getLocType() == BDLocation.TypeCriteriaException) {
                sb.append("\ndescribe : ");
                sb.append("无法获取有效定位依据导致定位失败,一般是由于手机的原因,处于飞行模式下一般会造成这种结果,可以试着重启手机");
            }
            UILog.i(sb.toString());
        }
    }
}

18 Source : ClientOption.java
with Apache License 2.0
from dudu90

/**
 * Created by pitt on 2017/3/16.
 */
/**
 * 对百度和高德ClientOption的封装,使用时其中一个Option为null
 */
public clreplaced ClientOption {

    // 百度Client的Option
    private LocationClientOption mBaiduOption;

    // 高德Client的Option
    private AMapLocationClientOption mAmapOption;

    public ClientOption(final LocationClientOption option) {
        mBaiduOption = option;
    }

    public ClientOption(final AMapLocationClientOption option) {
        mAmapOption = option;
    }

    public LocationClientOption getBaiduOption() {
        return mBaiduOption;
    }

    public AMapLocationClientOption getAmapOption() {
        return mAmapOption;
    }
}

18 Source : HooweLocationProvider.java
with Apache License 2.0
from dreamfish797

/**
 * Created by DreamFisn on 2017/8/26.
 */
public clreplaced HooweLocationProvider {

    public static final String TAG = "HooweLocationProvider";

    private Context mContext;

    private LocationClientOption mOption;

    private HooweLocationTracker mTracker;

    private boolean hasTracker = false;

    // 默认定位频度 1 秒/次 (必须 >= 1 秒)
    private static int LOCATION_FREQUENCY = 1000;

    // 定位频度
    private int mFrequency = LOCATION_FREQUENCY;

    /**
     * 类级的内部类,也就是静态类的成员式内部类,该内部类的实例与外部类的实例
     * 没有绑定关系,而且只有被调用时才会装载,从而实现了延迟加载
     *
     * @author dream
     */
    private static clreplaced LocationProviderHolder {

        /**
         * 静态初始化器,由JVM来保证线程安全
         */
        private static HooweLocationProvider instance = new HooweLocationProvider();
    }

    /**
     * 私有化构造方法
     */
    private HooweLocationProvider() {
    }

    public static HooweLocationProvider getInstance() {
        return LocationProviderHolder.instance;
    }

    /**
     * initialize Map SDK
     *
     * @param context
     */
    public void initialize(Context context) {
        this.mContext = context;
        SDKInitializer.initialize(context);
    }

    /**
     * 是否存在追踪任务
     *
     * @return
     */
    public boolean isHasTracker() {
        return hasTracker;
    }

    public int getmFrequency() {
        return mFrequency;
    }

    /**
     * 获取当前位置(实时定位)
     *
     * @param listener
     */
    public void getCurrentLocation(OnLocationUpdatedListener listener) {
        this.getCurrentLocation(null, listener);
    }

    /**
     * 获取当前位置(实时定位)
     *
     * @param mOption
     * @param listener
     */
    public void getCurrentLocation(LocationClientOption mOption, OnLocationUpdatedListener listener) {
        if (hasTracker) {
            // 有追踪任务在运行
            // 获取最新位置返回
            HooweLocation location = LocationDBHelper.getHelper(mContext).getLatestLocation();
            listener.onReceiveLocation(location);
        } else {
            HooweLocationTracker locationTracker = new HooweLocationTracker(mContext);
            if (mOption != null) {
                locationTracker.setLocationOption(mOption);
            } else {
                locationTracker.setLocationOption(locationTracker.getDefaultLocationClientOption());
            }
            locationTracker.registerListener(listener);
            locationTracker.start();
        }
    }

    /**
     * 异步 获取特定时间该设备的位置(前提是指定时间开启过位置追踪)
     *
     * @param time
     */
    public void getLocationByTime(long time, OnLocationUpdatedListener listener) {
        HooweLocation location = LocationDBHelper.getHelper(mContext).locDBLoadByTime(time);
        if (location != null) {
            listener.onReceiveLocation(location);
        } else {
            listener.onLocationTrackerNotRun();
        }
    }

    /**
     * 异步 获取特定时间断该设备的位置(前提是指定时间断开启过位置追踪)
     *
     * @param startTime
     * @param endTime
     */
    public void getLocationByPeriod(Long startTime, long endTime, OnLocationUpdatedListener listener) {
        List<HooweLocation> locationList = new ArrayList<>();
        locationList.addAll(LocationDBHelper.getHelper(mContext).locDBLoadByPeriod(startTime, endTime));
        if (locationList.size() > 0) {
            listener.onReceiveLocation(locationList);
        } else {
            listener.onLocationTrackerNotRun();
        }
    }

    /**
     * 同步 获取特定时间该设备的位置(前提是指定时间开启过位置追踪)
     *
     * @param time
     */
    public HooweLocation getLocationByTime(long time) {
        return LocationDBHelper.getHelper(mContext).locDBLoadByTime(time);
    }

    /**
     * 同步 获取特定时间断该设备的位置(前提是指定时间断开启过位置追踪)
     *
     * @param startTime
     * @param endTime
     */
    public List<HooweLocation> getLocationByPeriod(Long startTime, long endTime) {
        return LocationDBHelper.getHelper(mContext).locDBLoadByPeriod(startTime, endTime);
    }

    /**
     * 开始位置追踪 (启动追踪服务)
     */
    public void startTracker() {
        Intent intent = new Intent(mContext, TrackerService.clreplaced);
        mContext.startService(intent);
    }

    /**
     * 开始位置追踪
     *
     * @param listener
     */
    public void startTracker(OnLocationUpdatedListener listener) {
        this.startTracker(null, listener);
    }

    /**
     * 开始位置追踪
     *
     * @param mOption   定位配置
     * @param listener
     */
    public void startTracker(LocationClientOption mOption, OnLocationUpdatedListener listener) {
        if (!hasTracker) {
            mTracker = new HooweLocationTracker(mContext);
            mTracker.setLocationOption(mOption);
            mTracker.registerListener(listener);
            mTracker.start();
            hasTracker = true;
        } else {
            // 已经存在追踪任务
            // TODO: 2017/8/28 回调通知调用者
            if (listener != null) {
                listener.onLocationTrackerExist();
            }
        }
    }

    /**
     * 结束位置追踪
     */
    public void endTracker() {
        if (mTracker != null) {
            mTracker.unregisterListener();
            mTracker.stop();
        }
        hasTracker = false;
        if (ServiceUtils.isServiceRun(mContext, ServiceUtils.TRACKER_SERVICE_CLreplaced_NAME)) {
            Intent intent = new Intent(mContext, TrackerService.clreplaced);
            mContext.stopService(intent);
        }
    }
}

17 Source : IndexDelegate.java
with MIT License
from zion223

public clreplaced IndexDelegate extends BottomItemDelegate implements View.OnFocusChangeListener {

    @BindView(R2.id.rv_index)
    RecyclerView mBannerRecycleView;

    @BindView(R2.id.rl_index_search)
    RelativeLayout mRlSearch;

    @BindView(R2.id.app_bar_layout_index)
    AppBarLayout mAppBarLayout;

    @BindView(R2.id.iv_index_message)
    ImageView mIconMessage;

    @BindView(R2.id.tb_index)
    Toolbar mToolBar;

    @BindView(R2.id.rv_index_spec)
    RecyclerView mSpecRecyclerView;

    @BindView(R2.id.tl_index_sort)
    TabLayout mTabLayout;

    @BindView(R2.id.vp_index_sort)
    ViewPager mViewPager;

    @BindView(R2.id.tv_index_location)
    TextView mTvLocation;

    @BindView(R2.id.et_index_search)
    EditText mEtSearch;

    @BindView(R2.id.nestScrollView)
    NestedScrollView mNestScrollView;

    @BindView(R2.id.refresh_layout_index)
    SmartRefreshLayout mRefreshLayout;

    @BindView(R2.id.iv_cart)
    CircleImageView mIvCartView;

    private MultipleRecyclerAdapter mAdapter = null;

    private List<SpecZoneBean> mSpecData = null;

    /**
     * 地理位置
     */
    private MyLocationListener myListener = new MyLocationListener();

    private LocationClient mLocationClient = null;

    private LocationClientOption option = null;

    /**
     * 购物车图案UI
     */
    // 上下滑动的距离
    private float startY;

    // 动画移动的距离
    private int moveDistance;

    // 标记图片是否显示
    private volatile boolean isShowFloatImage = true;

    // 计时器
    private Timer timer;

    // 记录抬起的时间
    private long upTime;

    /**
     * 需要动态申请的权限
     */
    private final String[] perms = { Manifest.permission.READ_PHONE_STATE, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE };

    @OnClick(R2.id.tv_index_location)
    void onClickLocation() {
        getParentDelegate().getSupportDelegate().startForResult(LocationDelegate.create(mTvLocation.getText().toString()), 11);
    }

    @Override
    public Object setLayout() {
        return R.layout.delegate_index;
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, @NonNull View view) {
        // 渐变式状态栏
        StatusBarUtil.setGradientColor(getProxyActivity(), mToolBar);
        initNormalView();
        initRecyclerView();
        initData();
    }

    @Override
    public void onLazyInitView(@Nullable Bundle savedInstanceState) {
        super.onLazyInitView(savedInstanceState);
        initTouchListener();
        initTabLayout();
        if (EasyPermissions.hasPermissions(Latte.getApplication(), perms)) {
            initLocation();
        } else {
            EasyPermissions.requestPermissions(this, "请打开相关权限", 1, perms);
        }
    }

    private void initNormalView() {
        mRefreshLayout.setRefreshHeader(new CustomRefreshHeader(getActivity()));
        // 下拉高度
        mRefreshLayout.setHeaderHeight(80);
        mRefreshLayout.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {

            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                mRefreshLayout.finishLoadMore(2000, true, false);
            }

            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                mRefreshLayout.finishRefresh(2000, true, false);
            }
        });
        mAppBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {

            @Override
            public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
                int toolBarHeight = mToolBar.getHeight();
                // Log.e(TAG, "verticalOffset: " + verticalOffset +" toolBarHeight:"+toolBarHeight);
                if (Math.abs(verticalOffset) <= toolBarHeight) {
                    mToolBar.setAlpha(1.0f - Math.abs(verticalOffset) * 1.0f / toolBarHeight);
                }
            }
        });
        mNestScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {

            @Override
            public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
                if (scrollY > oldScrollY) {
                // Log.e(TAG, "上滑" + "scrollY " + scrollY + " oldScrollY " + oldScrollY );
                // mToolBar.setBackgroundColor(Color.WHITE);
                // mRlSearch.setBackgroundColor(Color.WHITE);
                // mToolBar.setVisibility(View.VISIBLE);
                }
                if (scrollY < oldScrollY) {
                // Log.e(TAG, "下滑" + "scrollY" + scrollY + ":" + "oldScrollY" + oldScrollY);
                // mRlSearch.setBackground(getResources().getDrawable(R.drawable.index_toorbar_backgroundtwo));
                // mToolBar.setBackground(getResources().getDrawable(R.drawable.index_toorbar_background));
                // mToolBar.setVisibility(View.GONE);
                }
                if (scrollY == 0) {
                // Log.e(TAG, "滑到顶部");
                // mToolBar.setBackground(getResources().getDrawable(R.drawable.index_toorbar_background));
                // mToolBar.setVisibility(View.VISIBLE);
                }
                if (scrollY == (v.getChildAt(0).getMeasuredHeight() - v.getMeasuredHeight())) {
                // Log.e(TAG, "滑到底部");
                }
            }
        });
        mIvCartView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

            @Override
            public void onGlobalLayout() {
                moveDistance = DimenUtil.getScreenWidth() - mIvCartView.getRight() + mIvCartView.getWidth() / 2;
                mIvCartView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
        });
    }

    private void initTouchListener() {
        getProxyActivity().setListener(new ProxyActivity.OnTouchListener() {

            @Override
            public void onTouch(MotionEvent event) {
                switch(event.getAction()) {
                    // 手指按下
                    case MotionEvent.ACTION_DOWN:
                        if (System.currentTimeMillis() - upTime > 1000) {
                            if (timer != null) {
                                timer.cancel();
                            }
                        }
                        startY = event.getY();
                        break;
                    // 手指滑动 状态
                    case MotionEvent.ACTION_MOVE:
                        if (Math.abs(startY - event.getY()) > 10) {
                            if (isShowFloatImage) {
                                hideFloatImage(moveDistance);
                            }
                        }
                        startY = event.getY();
                        break;
                    // 手指抬起后 1s后显示悬浮按钮
                    case MotionEvent.ACTION_UP:
                        if (!isShowFloatImage) {
                            upTime = System.currentTimeMillis();
                            timer = new Timer();
                            timer.schedule(new FloatTask(), 1000);
                        }
                        break;
                }
            }
        });
    }

    private void initTabLayout() {
        final String[] mreplacedles = { "全部", "晚餐", "人气", "必选" };
        final List<Fragment> mFragments = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            mFragments.add(new IndexTabDelegate());
        }
        final TabPagerAdapter adapter = new TabPagerAdapter(getChildFragmentManager(), mreplacedles, mFragments);
        mViewPager.setAdapter(adapter);
        mViewPager.setOffscreenPageLimit(4);
        mTabLayout.setTabMode(TabLayout.MODE_FIXED);
        mTabLayout.setBackgroundColor(Color.WHITE);
        mTabLayout.setupWithViewPager(mViewPager);
    }

    private void initRecyclerView() {
        // 总的SpanCount大小10 通过spanSize进行填充
        final GridLayoutManager manager = new GridLayoutManager(getContext(), 10);
        mBannerRecycleView.setLayoutManager(manager);
        // 添加分割线
        // mBannerRecycleView.addItemDecoration(BaseDecoration.create(ContextCompat.getColor(getContext(), R.color.app_background), 5));
        // 传递this 跳转时有EcBottomDelegate 传递getParentDelegate():ecBottomDelegate 跳转时无EcBottomDelegate
        mBannerRecycleView.addOnItemTouchListener(IndexItemClickListener.create(this));
        // 瀑布流
        final StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
        mSpecRecyclerView.setLayoutManager(staggeredGridLayoutManager);
    }

    private void initData() {
        // 加载广告数据和分类数据
        Observable<String> homeObservable = RestClient.builder().url("api/home").build().get().subscribeOn(Schedulers.io());
        // 加载特色专区数据
        Observable<String> specObservable = RestClient.builder().url("api/spec").build().get().subscribeOn(Schedulers.io());
        Disposable dis = Observable.zip(homeObservable, specObservable, new BiFunction<String, String, IndexAndSpecBean>() {

            @Override
            public IndexAndSpecBean apply(String s, String s2) {
                IndexAndSpecBean indexAndSpecBean = new IndexAndSpecBean();
                indexAndSpecBean.data1 = s;
                indexAndSpecBean.data2 = s2;
                return indexAndSpecBean;
            }
        }).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<IndexAndSpecBean>() {

            @Override
            public void accept(IndexAndSpecBean indexAndSpecBean) {
                mAdapter = MultipleRecyclerAdapter.create(new IndexDataConverter().setJsonData(indexAndSpecBean.data1));
                mAdapter.openLoadAnimation();
                mBannerRecycleView.setAdapter(mAdapter);
                mSpecData = new SpecZoneDataConverter().convert(indexAndSpecBean.data2);
                final SpecZoneAdapter mSpecZoneAdapter = new SpecZoneAdapter(R.layout.item_multiple_spec, R.layout.item_multiple_spec_header, mSpecData);
                mSpecRecyclerView.setAdapter(mSpecZoneAdapter);
            }
        }, new Consumer<Throwable>() {

            @Override
            public void accept(Throwable throwable) {
                ToastUtils.showLong("数据获取失败");
            }
        });
    }

    /**
     * 跳转到 SearchDelegate
     */
    @Override
    public void onFocusChange(View view, boolean hasFocus) {
    }

    @Override
    public void onFragmentResult(int requestCode, int resultCode, Bundle data) {
        final String address = data.getString("address");
        mTvLocation.setText(address);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mLocationClient.stop();
    }

    // 进入购物车界面
    @OnClick(R2.id.iv_cart)
    void onClickViewCart() {
    // getParentDelegate() : EcBottomDelegate
    // 切换Delegate
    }

    @Override
    public FragmentAnimator onCreateFragmentAnimator() {
        return new DefaultHorizontalAnimator();
    }

    private clreplaced FloatTask extends TimerTask {

        @Override
        public void run() {
            // ui线程中执行
            Latte.getHandler().post(new Runnable() {

                @Override
                public void run() {
                    showFloatImage();
                }
            });
        }
    }

    private void showFloatImage() {
        isShowFloatImage = true;
        TranslateAnimation ta = new TranslateAnimation(moveDistance, 0, 0, 0);
        ta.setDuration(300);
        AlphaAnimation aa = new AlphaAnimation(0.5f, 1.0f);
        aa.setDuration(300);
        AnimationSet set = new AnimationSet(true);
        // 动画完成后不回到原位  true:persist 默认值为false
        set.setFillAfter(true);
        set.addAnimation(ta);
        set.addAnimation(aa);
        mIvCartView.startAnimation(set);
    }

    private void hideFloatImage(int moveDistance) {
        isShowFloatImage = false;
        TranslateAnimation ta = new TranslateAnimation(0, moveDistance, 0, 0);
        ta.setDuration(300);
        AlphaAnimation aa = new AlphaAnimation(1.0f, 0.5f);
        aa.setDuration(300);
        AnimationSet set = new AnimationSet(true);
        // 动画完成后不回到原位  true:persist 默认值为false
        set.setFillAfter(true);
        set.addAnimation(ta);
        set.addAnimation(aa);
        mIvCartView.startAnimation(set);
    }

    public clreplaced MyLocationListener extends BDAbstractLocationListener {

        @Override
        public void onReceiveLocation(BDLocation location) {
            if (location == null) {
                return;
            }
            mTvLocation.setText(location.getAddrStr().substring(5));
        }
    }

    private void initLocation() {
        // 声明LocationClient类
        mLocationClient = new LocationClient(getContext());
        option = new LocationClientOption();
        option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
        option.setCoorType("bd09ll");
        option.setOpenGps(true);
        option.setLocationNotify(true);
        option.setIgnoreKillProcess(true);
        option.SetIgnoreCacheException(false);
        option.setEnableSimulateGps(false);
        option.setIsNeedLocationDescribe(true);
        option.setIsNeedLocationPoiList(true);
        option.setIsNeedAddress(true);
        mLocationClient.setLocOption(option);
        // 注册监听函数
        mLocationClient.registerLocationListener(myListener);
        mLocationClient.start();
    }
}

17 Source : BMapSDKHelper.java
with GNU General Public License v3.0
from zhangneng

/**
 * 百度定位SDK帮助类
 * Created by pengl on 2017/8/2 0002.
 */
public clreplaced BMapSDKHelper {

    /**
     * SDK定位客户端,用来发起定位等
     */
    private LocationClient locationClient;

    /**
     * SDK定位客户端可选项
     */
    private LocationClientOption locationOption;

    private BDLocationListener locationListener;

    private Context context;

    public BMapSDKHelper(Context context, BDLocationListener listener) {
        this.context = context.getApplicationContext();
        this.locationListener = listener;
        init();
    }

    /**
     * 初始化客户端
     */
    private void init() {
        locationClient = new LocationClient(context);
        locationOption = getDefaultOption();
        // 设置可选参数
        locationClient.setLocOption(locationOption);
        // 设置回调监听
        locationClient.registerLocationListener(locationListener);
    }

    /**
     * 得到默认的定位参数
     * @return
     */
    private LocationClientOption getDefaultOption() {
        LocationClientOption mOption = new LocationClientOption();
        // 可选,默认gcj02,设置返回的定位结果坐标系,如果配合百度地图使用,建议设置为bd09ll;
        mOption.setCoorType("bd09ll");
        // 可选,默认0,即仅定位一次,设置发起定位请求的间隔需要大于等于1000ms才是有效的
        mOption.setScanSpan(0);
        // 可选,设置是否需要地址信息,默认不需要
        mOption.setIsNeedAddress(true);
        mOption.setAddrType("all");
        // 可选,设置是否需要地址描述
        mOption.setIsNeedLocationDescribe(true);
        // 可选,设置是否需要设备方向结果
        mOption.setNeedDeviceDirect(false);
        // 可选,默认false,设置是否当gps有效时按照1S1次频率输出GPS结果
        mOption.setLocationNotify(false);
        // 可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死
        mOption.setIgnoreKillProcess(true);
        // 可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近”
        mOption.setIsNeedLocationDescribe(true);
        // 可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到
        mOption.setIsNeedLocationPoiList(true);
        // 可选,默认false,设置是否收集CRASH信息,默认收集
        mOption.SetIgnoreCacheException(false);
        return mOption;
    }

    /**
     * 开始定位
     */
    public void startLocation() {
        // 启动定位
        locationClient.start();
    }

    /**
     * 停止定位
     */
    public void stopLocation() {
        locationClient.stop();
    }

    /**
     * 销毁定位
     */
    public void destroyLocation() {
        if (null != locationClient) {
            /**
             * 如果AMapLocationClient是在当前Activity实例化的,
             * 在Activity的onDestroy中一定要执行AMapLocationClient的onDestroy
             */
            locationClient.stop();
            locationClient = null;
            locationOption = null;
            context = null;
        }
    }
}

17 Source : BMapSDKHelper.java
with GNU General Public License v3.0
from zhangneng

/**
 * 得到默认的定位参数
 * @return
 */
private LocationClientOption getDefaultOption() {
    LocationClientOption mOption = new LocationClientOption();
    // 可选,默认gcj02,设置返回的定位结果坐标系,如果配合百度地图使用,建议设置为bd09ll;
    mOption.setCoorType("bd09ll");
    // 可选,默认0,即仅定位一次,设置发起定位请求的间隔需要大于等于1000ms才是有效的
    mOption.setScanSpan(0);
    // 可选,设置是否需要地址信息,默认不需要
    mOption.setIsNeedAddress(true);
    mOption.setAddrType("all");
    // 可选,设置是否需要地址描述
    mOption.setIsNeedLocationDescribe(true);
    // 可选,设置是否需要设备方向结果
    mOption.setNeedDeviceDirect(false);
    // 可选,默认false,设置是否当gps有效时按照1S1次频率输出GPS结果
    mOption.setLocationNotify(false);
    // 可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死
    mOption.setIgnoreKillProcess(true);
    // 可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近”
    mOption.setIsNeedLocationDescribe(true);
    // 可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到
    mOption.setIsNeedLocationPoiList(true);
    // 可选,默认false,设置是否收集CRASH信息,默认收集
    mOption.SetIgnoreCacheException(false);
    return mOption;
}

17 Source : Activity_FoodDelivery.java
with Apache License 2.0
from yangxch

/**
 * 食品配送
 */
public clreplaced Activity_FoodDelivery extends BaseActivity implements SwipeRefreshLayout.OnRefreshListener {

    private ProgressDialog pg;

    // 无数据视图
    private View mEmptyView;

    private EmptyRecyclerView recyclerView;

    private SwipeRefreshLayout swipeRefreshLayout;

    // 配送订单列表
    private List<Order> orderDeliveryList = new ArrayList<>();

    // 商家列表
    private List<Business> businessList = new ArrayList<>();

    private MyLocationListener myListener = new MyLocationListener();

    public LocationClient mLocationClient = null;

    private LocationClientOption option = null;

    public static double longitude, lareplacedude;

    public static String address;

    @SuppressLint("HandlerLeak")
    private Handler handler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            pg.dismiss();
            switch(msg.what) {
                case 1:
                    Adapter_FoodDelivery adapter = new Adapter_FoodDelivery(orderDeliveryList, businessList, longitude, lareplacedude, address, Activity_FoodDelivery.this);
                    LinearLayoutManager layoutManager = new LinearLayoutManager(Activity_FoodDelivery.this);
                    recyclerView.setLayoutManager(layoutManager);
                    recyclerView.setAdapter(adapter);
                    recyclerView.setEmptyView(mEmptyView);
                    break;
                default:
                    break;
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_food_delivery);
        pg = new ProgressDialog(Activity_FoodDelivery.this);
        initView();
        location();
        getBusinessData();
        getFoodDeliveryData();
    }

    /**
     * 定位,获取当前位置信息
     */
    private void location() {
        // 声明LocationClient类
        mLocationClient = new LocationClient(getApplicationContext());
        initLocation();
        // 注册监听函数
        mLocationClient.registerLocationListener(myListener);
        mLocationClient.start();
    }

    private void initLocation() {
        // 利用LocationClientOption类配置定位SDK参数
        option = new LocationClientOption();
        option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
        // 可选,设置定位模式,默认高精度
        // LocationMode.Hight_Accuracy:高精度;
        // LocationMode. Battery_Saving:低功耗;
        // LocationMode. Device_Sensors:仅使用设备;
        option.setCoorType("bd09ll");
        // 可选,设置返回经纬度坐标类型,默认gcj02
        // gcj02:国测局坐标;
        // bd09ll:百度经纬度坐标;
        // bd09:百度墨卡托坐标;
        // 海外地区定位,无需设置坐标类型,统一返回wgs84类型坐标
        option.setOpenGps(true);
        // 可选,设置是否使用gps,默认false
        // 使用高精度和仅用设备两种定位模式的,参数必须设置为true
        option.setLocationNotify(true);
        // 可选,设置是否当GPS有效时按照1S/1次频率输出GPS结果,默认false
        option.setIgnoreKillProcess(true);
        // 可选,定位SDK内部是一个service,并放到了独立进程。
        // 设置是否在stop的时候杀死这个进程,默认(建议)不杀死,即setIgnoreKillProcess(true)
        option.SetIgnoreCacheException(false);
        // 可选,设置是否收集Crash信息,默认收集,即参数为false
        option.setEnableSimulateGps(false);
        // 可选,设置是否需要过滤GPS仿真结果,默认需要,即参数为false
        option.setIsNeedLocationDescribe(true);
        // 可选,是否需要位置描述信息,默认为不需要,即参数为false
        // 如果开发者需要获得当前点的位置信息,此处必须为true
        option.setIsNeedLocationPoiList(true);
        // 可选,是否需要周边POI信息,默认为不需要,即参数为false
        // 如果开发者需要获得周边POI信息,此处必须为true
        // 获取详细信息
        option.setIsNeedAddress(true);
        mLocationClient.setLocOption(option);
    // mLocationClient为第二步初始化过的LocationClient对象
    // 需将配置好的LocationClientOption对象,通过setLocOption方法传递给LocationClient对象使用
    // 更多LocationClientOption的配置,请参照类参考中LocationClientOption类的详细说明
    }

    public clreplaced MyLocationListener implements BDLocationListener {

        @Override
        public void onReceiveLocation(BDLocation arg0) {
            if (arg0.getLocType() == BDLocation.TypeGpsLocation || arg0.getLocType() == BDLocation.TypeNetWorkLocation) {
                longitude = arg0.getLongitude();
                lareplacedude = arg0.getLareplacedude();
                address = arg0.getAddrStr();
            // Util.showToast(Activity_FoodDelivery.this,longitude+"/"+lareplacedude+" "+address);
            }
        }
    }

    public static void actionStart(Context context) {
        Intent intent = new Intent(context, Activity_FoodDelivery.clreplaced);
        context.startActivity(intent);
    }

    /**
     * 获取商家信息(从MainActivity)
     */
    private void getBusinessData() {
        businessList = Activity_Main.businessList;
    }

    /**
     * 获取需要送餐的外卖数据
     */
    private void getFoodDeliveryData() {
        pg.setMessage("正在获取数据和定位信息...");
        pg.show();
        if (!Util.checkNetwork(this)) {
            pg.dismiss();
            return;
        }
        new Thread() {

            @Override
            public void run() {
                try {
                    // 获取订单
                    orderDeliveryList = RequestUtility.getOrdersList("201712dd70");
                    Message message = handler.obtainMessage();
                    message.what = 1;
                    handler.sendMessage(message);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
    }

    private void initView() {
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setreplacedle("");
        TextView toolbarText = (TextView) findViewById(R.id.toolbar_text);
        toolbarText.setText("送餐");
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
        mEmptyView = findViewById(R.id.id_empty_view);
        recyclerView = (EmptyRecyclerView) findViewById(R.id.recyclerView);
        // 刷新控件
        swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayoutOrderAll);
        swipeRefreshLayout.setOnRefreshListener(this);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch(item.gereplacedemId()) {
            case android.R.id.home:
                finish();
                break;
            default:
                break;
        }
        return true;
    }

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

    @Override
    public void onRefresh() {
        getFoodDeliveryData();
        new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    // 刷新控件停止两秒后消失
                    Thread.sleep(1000);
                    handler.post(new Runnable() {

                        @Override
                        public void run() {
                            swipeRefreshLayout.setRefreshing(false);
                        }
                    });
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}

17 Source : LocationService.java
with Apache License 2.0
from wangzhijun1124

public boolean setLocationOption(LocationClientOption option) {
    boolean isSuccess = false;
    if (option != null) {
        if (client.isStarted())
            client.stop();
        DIYoption = option;
        client.setLocOption(option);
    }
    return isSuccess;
}

17 Source : BaiduLocation.java
with Apache License 2.0
from LuoPeiQin

/**
 * @param option
 * @return isSuccessSetOption
 */
public boolean setLocationOption(LocationClientOption option) {
    boolean isSuccess = false;
    if (option != null) {
        if (client.isStarted())
            client.stop();
        DIYoption = option;
        client.setLocOption(option);
    }
    return isSuccess;
}

17 Source : LocationUtils.java
with Apache License 2.0
from fergus825

private void initLocation() {
    LocationClientOption option = new LocationClientOption();
    option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
    // 可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
    // 可选,默认gcj02,设置返回的定位结果坐标系
    option.setCoorType("bd09ll");
    int span = 100;
    // 大于等于1000ms时,使用定时定位模式。调用requestLocation()后,每隔设定的时间定定一次位
    option.setScanSpan(span);
    // 可选,设置是否需要地址信息,默认不需要
    option.setIsNeedAddress(true);
    // 可选,默认false,设置是否使用gps
    option.setOpenGps(true);
    // 可选,默认false,设置是否当GPS有效时按照1S/1次频率输出GPS结果
    option.setLocationNotify(true);
    // 可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近”
    option.setIsNeedLocationDescribe(true);
    // 可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到
    option.setIsNeedLocationPoiList(true);
    // 可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死
    option.setIgnoreKillProcess(false);
    // 可选,默认false,设置是否收集CRASH信息,默认收集
    option.SetIgnoreCacheException(false);
    // 可选,默认false,设置是否需要过滤GPS仿真结果,默认需要
    option.setEnableSimulateGps(false);
    mLocationClient.setLocOption(option);
    mLocationClient.registerLocationListener(new BDLocationListener() {

        @Override
        public void onReceiveLocation(BDLocation location) {
            // Receive Location
            StringBuffer sb = new StringBuffer(256);
            sb.append("定位时间: ");
            sb.append(location.getTime());
            sb.append(",纬度: ");
            sb.append(location.getLareplacedude());
            sb.append(",经度: ");
            sb.append(location.getLongitude());
            sb.append(",定位精度: ");
            sb.append(location.getRadius() + "米;");
            if (location.getLocType() == BDLocation.TypeGpsLocation) {
                // GPS定位结果
                /*  sb.append(";我的速度");
                     sb.append(location.getSpeed());// 单位:公里每小时*/
                // sb.append("\nsatellite : ");
                // sb.append(location.getSatelliteNumber());
                // sb.append("\nheight : ");
                // sb.append(location.getAlreplacedude());// 单位:米
                // sb.append("\ndirection : ");
                // sb.append(location.getDirection());// 单位度
                sb.append("所在地址: ");
                sb.append(location.getAddrStr());
                sb.append(";定位方式: ");
                sb.append("gps定位成功");
            } else if (location.getLocType() == BDLocation.TypeNetWorkLocation) {
                // 网络定位结果
                sb.append("所在位置: ");
                sb.append(location.getAddrStr());
            // 运营商信息
            // sb.append("\noperationers : ");
            // sb.append(location.getOperators());
            // sb.append(";定位方式: ");
            // sb.append("网络定位成功");
            } else if (location.getLocType() == BDLocation.TypeOffLineLocation) {
            // 离线定位结果
            // sb.append(";定位方式: ");
            // sb.append("离线定位成功,离线定位结果也是有效的");
            } else if (location.getLocType() == BDLocation.TypeServerError) {
            // sb.append(";定位方式: ");
            // sb.append("服务端网络定位失败,可以反馈IMEI号和大体定位时间到[email protected],会有人追查原因");
            } else if (location.getLocType() == BDLocation.TypeNetWorkException) {
            /*  sb.append(";定位方式: : ");
                     sb.append("网络不同导致定位失败,请检查网络是否通畅");*/
            } else if (location.getLocType() == BDLocation.TypeCriteriaException) {
            // sb.append(";定位方式:");
            // sb.append("无法获取有效定位依据导致定位失败,一般是由于手机的原因,处于飞行模式下一般会造成这种结果,可以试着重启手机");
            }
            sb.append(";位置描述: ");
            // 位置语义化信息
            sb.append(location.getLocationDescribe());
            // List<Poi> list = location.getPoiList();// POI数据
            // if (list != null) {
            // sb.append("\npoilist size = : ");
            // sb.append(list.size());
            // for (Poi p : list) {
            // sb.append("\npoi= : ");
            // sb.append(p.getId() + " " + p.getName() + " " + p.getRank());
            // }
            // }
            editor.putString("location", sb.toString()).commit();
            Log.i("111111111111", sb.toString());
        // Toast.makeText(context, prefs.getString("location",""), Toast.LENGTH_LONG).show();
        }
    });
}

17 Source : ClientOptionFactory.java
with Apache License 2.0
from dudu90

/**
 * @return Default LocationClientOption
 * 详情请查看{ http://wiki.lbsyun.baidu.com/cms/androidloc/doc/v7.1/index.html }
 */
private LocationClientOption getDefaultLocationClientOption() {
    final LocationClientOption option = new LocationClientOption();
    option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
    option.setIsNeedAddress(true);
    option.setIsNeedLocationDescribe(true);
    option.setNeedDeviceDirect(false);
    option.setLocationNotify(false);
    option.setIgnoreKillProcess(true);
    option.setIsNeedLocationDescribe(true);
    option.setIsNeedLocationPoiList(true);
    option.SetIgnoreCacheException(false);
    option.setIsNeedAlreplacedude(false);
    return option;
}

17 Source : TrackerService.java
with Apache License 2.0
from dreamfish797

/**
 * @return DefaultLocationClientOption
 */
public LocationClientOption getDefaultLocationClientOption() {
    LocationClientOption mOption = new LocationClientOption();
    mOption = new LocationClientOption();
    // 可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
    mOption.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
    // 可选,默认gcj02,设置返回的定位结果坐标系,如果配合百度地图使用,建议设置为bd09ll;
    mOption.setCoorType("bd09ll");
    // 可选,默认0,即仅定位一次,设置发起定位请求的间隔需要大于等于1000ms才是有效的
    mOption.setScanSpan(3000);
    // 可选,设置是否需要地址信息,默认不需要
    mOption.setIsNeedAddress(true);
    // 可选,设置是否需要设备方向结果
    mOption.setNeedDeviceDirect(true);
    // 可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近”
    mOption.setIsNeedLocationDescribe(true);
    // 可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到
    mOption.setIsNeedLocationPoiList(true);
    // 可选,默认false,设置定位时是否需要海拔信息,默认不需要,除基础定位版本都可用
    mOption.setIsNeedAlreplacedude(true);
    return mOption;
}

17 Source : BDLocationService.java
with Apache License 2.0
from devallever

private void initLocation() {
    LocationClientOption option = new LocationClientOption();
    // 可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
    option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
    // 可选,默认gcj02,设置返回的定位结果坐标系
    option.setCoorType("bd09ll");
    int span = 1000;
    // 可选,默认0,即仅定位一次,设置发起定位请求的间隔需要大于等于1000ms才是有效的
    option.setScanSpan(span);
    // 可选,设置是否需要地址信息,默认不需要
    option.setIsNeedAddress(true);
    // 可选,默认false,设置是否使用gps
    option.setOpenGps(true);
    // 可选,默认false,设置是否当gps有效时按照1S1次频率输出GPS结果
    option.setLocationNotify(true);
    // 可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近”
    option.setIsNeedLocationDescribe(true);
    // 可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到
    option.setIsNeedLocationPoiList(true);
    // 可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死
    option.setIgnoreKillProcess(false);
    // 可选,默认false,设置是否收集CRASH信息,默认收集
    option.SetIgnoreCacheException(false);
    // 可选,默认false,设置是否需要过滤gps仿真结果,默认需要
    option.setEnableSimulateGps(false);
    mLocationClient.setLocOption(option);
}

17 Source : MyBaiduLocation.java
with GNU General Public License v2.0
from CrazyRunning

private void initLockPst() {
    locationClient = new LocationClient(this.myContext);
    // 设置定位条件
    LocationClientOption option = new LocationClientOption();
    // 是否打开GPS
    option.setOpenGps(true);
    // 设置返回值的坐标类型。
    option.setCoorType("bd09ll");
    // 设置定位优先级
    option.setPriority(LocationClientOption.NetWorkFirst);
    // 设置产品线名称。强烈建议您使用自定义的产品线名称,方便我们以后为您提供更高效准确的定位服务。
    option.setProdName("LocationDemo");
    // 设置定时定位的时间间隔。单位毫秒
    option.setScanSpan(UPDATE_TIME);
    locationClient.setLocOption(option);
    // 注册位置监听器
    locationClient.registerLocationListener(new BDLocationListener() {

        @Override
        public void onReceiveLocation(BDLocation location) {
            // TODO Auto-generated method stub
            if (myBDcoordinate != null) {
                stopOpetateClient();
                // locationInfoTextView.setText("stop" + LOCATION_COUTNS);
                return;
            }
            if (LOCATION_COUTNS > 5) {
                stopOpetateClient();
                return;
            }
            if (location == null) {
                LOCATION_COUTNS++;
                return;
            }
            // location.getLocType();
            // location.getLareplacedude()
            // location.getLongitude();
            if (location.getLocType() != 161) {
                LOCATION_COUTNS++;
                return;
            }
            myBDcoordinate = new MyBDcoordinate();
            myBDcoordinate.Lareplacedude = location.getLareplacedude();
            myBDcoordinate.Longitude = location.getLongitude();
        }
    });
}

16 Source : LocationDelegate.java
with MIT License
from zion223

public clreplaced LocationDelegate extends LatteDelegate implements OnGetPoiSearchResultListener {

    @BindView(R2.id.tv_index_location_city)
    TextView mTvLocationCity;

    @BindView(R2.id.tv_location_detail)
    TextView mTvLocationDetail;

    @BindView(R2.id.rv_location_address)
    RecyclerView mRvAddress;

    @BindView(R2.id.rv_location_around)
    RecyclerView mRvRoundAddress;

    @BindView(R2.id.mv_location_hidden)
    MapView mMapView;

    private AddressAdapter mAdapter = null;

    // 地图定位
    private MyLocationListener myListener = new MyLocationListener();

    public LocationClient mLocationClient = null;

    private LocationClientOption option = null;

    // poi检索
    // 反向地理解析,获取周边poi
    private GeoCoder mGeoCoder;

    private PoiSearch mPoiSearch = null;

    // 地点检索输入提示检索(Sug检索)
    private SuggestionSearch mSuggestionSearch = null;

    // 地图中心点坐标
    private LatLng center;

    // poi检索半径
    private int radius = 600;

    // 分页页码
    private int loadIndex = 0;

    private int pageSize = 50;

    // 地理反向解析获取的poi
    private List<PoiInfo> poiInfoListForGeoCoder = new ArrayList<>();

    // 检索结果集合
    private List<PoiInfo> poiInfoListForSearch = new ArrayList<>();

    private NearbyAddressAdapter mNearbyAddressAdapter;

    private String cityName = "";

    private String keyword = "";

    private static final String ARGS_LOCATION_DETAIL = "ARGS_LOCATION_DETAIL";

    private String currentAddr = null;

    public static LocationDelegate create(String address) {
        final Bundle args = new Bundle();
        args.putString(ARGS_LOCATION_DETAIL, address);
        final LocationDelegate delegate = new LocationDelegate();
        delegate.setArguments(args);
        return delegate;
    }

    @Override
    public Object setLayout() {
        return R.layout.delegate_location;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, @NonNull View view) throws Exception {
        replacedert getArguments() != null;
        final String detail = getArguments().getString(ARGS_LOCATION_DETAIL);
        mTvLocationDetail.setText(detail);
        // 我的收货地址
        initMyAddress();
        // 附近的地址
        initGeoCoder();
        initPoiSearch();
        // 建议搜索
        // initSuggestionSearch();
        initLocation();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        mLocationClient.stop();
    }

    private void initMyAddress() {
        // 我的收货地址
        final LinearLayoutManager manager = new LinearLayoutManager(getContext());
        mRvAddress.setLayoutManager(manager);
        RestClient.builder().url("api/address").success(new ISuccess() {

            @Override
            public void onSuccess(String response) {
                final DataConverter converter = new AddressDataConverter().setJsonData(response);
                mAdapter = new AddressAdapter(converter.convert());
                mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {

                    @Override
                    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                        final MultipleItemEnreplacedy enreplacedy = (MultipleItemEnreplacedy) adapter.gereplacedem(position);
                        replacedert enreplacedy != null;
                        final String address = enreplacedy.getField(AddressItemFields.ADDRESS_PREFIX);
                        final Bundle bundle = new Bundle();
                        bundle.putString("address", address);
                        getSupportDelegate().setFragmentResult(RESULT_OK, bundle);
                        getSupportDelegate().onDestroy();
                        getSupportDelegate().pop();
                    }
                });
                mRvAddress.setAdapter(mAdapter);
            }
        }).build().get();
    }

    private void initLocation() {
        // 声明LocationClient类 使用ApplicationContext
        mLocationClient = new LocationClient(getProxyActivity().getApplicationContext());
        // 利用LocationClientOption类配置定位SDK参数
        option = new LocationClientOption();
        option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
        // 可选,设置定位模式,默认高精度  LocationMode.Hight_Accuracy:高精度; LocationMode. Battery_Saving:低功耗; LocationMode. Device_Sensors:仅使用设备;
        option.setCoorType("bd09ll");
        // 可选,设置返回经纬度坐标类型,默认gcj02
        // gcj02:国测局坐标;
        // bd09ll:百度经纬度坐标;
        // bd09:百度墨卡托坐标;
        // 海外地区定位,无需设置坐标类型,统一返回wgs84类型坐标
        option.setOpenGps(true);
        // 可选,设置是否使用gps,默认false
        // 使用高精度和仅用设备两种定位模式的,参数必须设置为true
        option.setLocationNotify(true);
        // 可选,设置是否当GPS有效时按照1S/1次频率输出GPS结果,默认false
        option.setIgnoreKillProcess(true);
        // 可选,定位SDK内部是一个service,并放到了独立进程。
        // 设置是否在stop的时候杀死这个进程,默认(建议)不杀死,即setIgnoreKillProcess(true)
        option.SetIgnoreCacheException(false);
        // 可选,设置是否收集Crash信息,默认收集,即参数为false
        option.setEnableSimulateGps(false);
        // 可选,设置是否需要过滤GPS仿真结果,默认需要,即参数为false
        option.setIsNeedLocationDescribe(true);
        // 可选,是否需要位置描述信息,默认为不需要,即参数为false
        option.setIsNeedLocationPoiList(true);
        // 可选,是否需要周边POI信息,默认为不需要,即参数为false
        // 获取详细信息
        option.setIsNeedAddress(true);
        // 设置扫描间隔
        // option.setScanSpan(10000);
        mLocationClient.setLocOption(option);
        // 注册监听函数
        mLocationClient.registerLocationListener(myListener);
        mLocationClient.start();
    }

    private void initGeoCoder() {
        mGeoCoder = GeoCoder.newInstance();
        mGeoCoder.setOnGetGeoCodeResultListener(new OnGetGeoCoderResultListener() {

            // 地理编码检索监听器
            @Override
            public void onGetGeoCodeResult(GeoCodeResult geoCodeResult) {
            }

            // 逆地理编码检索监听器
            @Override
            public void onGetReverseGeoCodeResult(ReverseGeoCodeResult reverseGeoCodeResult) {
                if (poiInfoListForGeoCoder != null) {
                    poiInfoListForGeoCoder.clear();
                }
                if (reverseGeoCodeResult.error.equals(SearchResult.ERRORNO.NO_ERROR)) {
                    // 获取城市
                    ReverseGeoCodeResult.AddressComponent addressComponent = reverseGeoCodeResult.getAddressDetail();
                    cityName = addressComponent.city;
                    // 获取poi列表
                    if (reverseGeoCodeResult.getPoiList() != null) {
                        poiInfoListForGeoCoder = reverseGeoCodeResult.getPoiList();
                    }
                }
                initGeoCoderListView();
            }
        });
    }

    private void initGeoCoderListView() {
        mNearbyAddressAdapter = new NearbyAddressAdapter(poiInfoListForGeoCoder);
        mNearbyAddressAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {

            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                final PoiInfo info = (PoiInfo) adapter.gereplacedem(position);
                replacedert info != null;
                final Bundle bundle = new Bundle();
                bundle.putString("address", info.getAddress());
                getSupportDelegate().setFragmentResult(RESULT_OK, bundle);
                getSupportDelegate().onDestroy();
                getSupportDelegate().pop();
            }
        });
        final LinearLayoutManager manager = new LinearLayoutManager(getContext());
        if (mRvRoundAddress != null) {
            mRvRoundAddress.setLayoutManager(manager);
            mRvRoundAddress.setAdapter(mNearbyAddressAdapter);
        }
    }

    private void initPoiSearch() {
        // 初始化搜索模块,注册搜索事件监听
        mPoiSearch = PoiSearch.newInstance();
        mPoiSearch.setOnGetPoiSearchResultListener(this);
    }

    @OnClick(R2.id.iv_location_backarrow)
    public void onViewClickedBack(View view) {
        getSupportDelegate().pop();
    }

    @OnClick(R2.id.tv_location_relocation)
    public void onClickReLocation(View view) {
        if (currentAddr != null) {
            mTvLocationDetail.setText(currentAddr.substring(5));
        }
    }

    @OnClick(R2.id.tv_index_location_city)
    public void onClickPickCity(View view) {
        final List<HotCity> hotCities = new ArrayList<>();
        // code为城市代码
        hotCities.add(new HotCity("北京", "北京", "101010100"));
        hotCities.add(new HotCity("上海", "上海", "101020100"));
        hotCities.add(new HotCity("广州", "广东", "101280101"));
        hotCities.add(new HotCity("深圳", "广东", "101280601"));
        hotCities.add(new HotCity("杭州", "浙江", "101210101"));
        replacedert getActivity() != null;
        // activity或者fragment
        CityPicker.from(getActivity()).enableAnimation(// 启用动画效果,默认无
        true).setLocatedCity(null).setHotCities(// 指定热门城市
        hotCities).setOnPickListener(new OnPickListener() {

            @Override
            public void onPick(int position, City data) {
                mTvLocationCity.setText(data.getName());
            }

            @Override
            public void onCancel() {
                Toast.makeText(Latte.getApplication(), "取消选择", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onLocate() {
                // 定位接口,需要APP自身实现,这里模拟一下定位
                new Handler().postDelayed(new Runnable() {

                    @Override
                    public void run() {
                    // 定位完成之后更新数据
                    // CityPicker.getInstance()
                    // .locateComplete(new LocatedCity("深圳", "广东", "101280601"), LocateState.SUCCESS);
                    }
                }, 3000);
            }
        }).show();
    }

    @Override
    public void onGetPoiResult(PoiResult poiResult) {
        if (poiInfoListForSearch != null) {
            poiInfoListForSearch.clear();
        }
        if (poiResult == null || poiResult.error == SearchResult.ERRORNO.RESULT_NOT_FOUND) {
            Toast.makeText(getContext(), "未找到结果", Toast.LENGTH_LONG).show();
            // initPoiSearchListView();
            return;
        }
        if (poiResult.error == SearchResult.ERRORNO.NO_ERROR) {
            poiInfoListForSearch = poiResult.getAllPoi();
            // showSeachView();
            initPoiSearchListView();
            return;
        }
        if (poiResult.error == SearchResult.ERRORNO.AMBIGUOUS_KEYWORD) {
            // 当输入关键字在本市没有找到,但在其他城市找到时,返回包含该关键字信息的城市列表
            String strInfo = "在";
            for (CityInfo cityInfo : poiResult.getSuggestCityList()) {
                strInfo += cityInfo.city;
                strInfo += ",";
            }
            strInfo += "找到结果";
            Toast.makeText(getContext(), strInfo, Toast.LENGTH_LONG).show();
        }
    }

    // 初始化搜索建议
    private void initPoiSearchListView() {
    }

    @Override
    public void onGetPoiDetailResult(PoiDetailResult poiDetailResult) {
    }

    @Override
    public void onGetPoiDetailResult(PoiDetailSearchResult poiDetailSearchResult) {
    }

    @Override
    public void onGetPoiIndoorResult(PoiIndoorResult poiIndoorResult) {
    }

    public clreplaced MyLocationListener extends BDAbstractLocationListener {

        @Override
        public void onReceiveLocation(BDLocation location) {
            if (location == null) {
                return;
            }
            if (location.getLocType() == BDLocation.TypeGpsLocation || location.getLocType() == BDLocation.TypeNetWorkLocation) {
                currentAddr = location.getAddrStr();
                // 当前所在位置
                LatLng currentLatLng = new LatLng(location.getLareplacedude(), location.getLongitude());
                mGeoCoder.reverseGeoCode(new ReverseGeoCodeOption().location(currentLatLng).radius(radius));
            }
        }
    }
}

16 Source : GpsUtil.java
with Apache License 2.0
from yangxch

private void initLocation() {
    LocationClientOption option = new LocationClientOption();
    option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
    // 可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
    // option.setCoorType("bd09ll");//可选,默认gcj02,设置返回的定位结果坐标系
    // int span=1000;
    // option.setScanSpan(span);//可选,默认0,即仅定位一次,设置发起定位请求的间隔需要大于等于1000ms才是有效的
    // 可选,设置是否需要地址信息,默认不需要
    option.setIsNeedAddress(true);
    // option.setOpenGps(true);//可选,默认false,设置是否使用gps
    // option.setLocationNotify(true);//可选,默认false,设置是否当gps有效时按照1S1次频率输出GPS结果
    // option.setIsNeedLocationDescribe(true);//可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近”
    // option.setIsNeedLocationPoiList(true);//可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到
    // 可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死
    option.setIgnoreKillProcess(false);
    // 可选,默认false,设置是否收集CRASH信息,默认收集
    option.SetIgnoreCacheException(true);
    // 可选,默认false,设置是否需要过滤gps仿真结果,默认需要
    option.setEnableSimulateGps(false);
    mLocationClient.setLocOption(option);
}

16 Source : Activity_Location.java
with Apache License 2.0
from yangxch

public clreplaced Activity_Location extends BaseActivity implements View.OnClickListener {

    private LinearLayout back_lay;

    private TextView replacedle, custom_made;

    private TextView tv_longitude, tv_lareplacedude, tv_address;

    private MapView mMapView = null;

    private BaiduMap mBaiduMap = null;

    // 判断是否是第一次进入应用
    private boolean isFirstLocation = true;

    private LatLng latLng;

    private MyLocationListener myListener = new MyLocationListener();

    public LocationClient mLocationClient = null;

    private LocationClientOption option = null;

    private double longitude, lareplacedude;

    private String address;

    private void findViewById() {
        back_lay = (LinearLayout) findViewById(R.id.back_lay);
        replacedle = (TextView) findViewById(R.id.replacedle);
        custom_made = (TextView) findViewById(R.id.custom_made);
        replacedle.setText("定位");
        custom_made.setText("确定");
        mMapView = (MapView) findViewById(R.id.bmapView);
        tv_longitude = (TextView) findViewById(R.id.tv_longitude);
        tv_lareplacedude = (TextView) findViewById(R.id.tv_lareplacedude);
        tv_address = (TextView) findViewById(R.id.tv_address);
        back_lay.setOnClickListener(this);
        custom_made.setOnClickListener(this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SDKInitializer.initialize(getApplicationContext());
        setContentView(R.layout.activity_location);
        findViewById();
        initMap();
        // 声明LocationClient类
        mLocationClient = new LocationClient(getApplicationContext());
        initLocation();
        // 注册监听函数
        mLocationClient.registerLocationListener(myListener);
        mLocationClient.start();
        mBaiduMap.setOnMapClickListener(new OnMapClickListener() {

            @Override
            public boolean onMapPoiClick(MapPoi arg0) {
                // TODO Auto-generated method stub
                LatLng latLng = arg0.getPosition();
                longitude = latLng.longitude;
                lareplacedude = latLng.lareplacedude;
                address = arg0.getName() + "";
                // 小数位数太长,只显示一部分(上传的位置还是真实经纬度)
                String str_longitude = subStringForLocation(String.valueOf(longitude));
                String str_lareplacedude = subStringForLocation(String.valueOf(lareplacedude));
                tv_longitude.setText(str_longitude);
                tv_lareplacedude.setText(str_lareplacedude);
                tv_address.setText(address);
                MyLocationData.Builder locationBuilder = new MyLocationData.Builder();
                locationBuilder.lareplacedude(lareplacedude);
                locationBuilder.longitude(longitude);
                MyLocationData locationData = locationBuilder.build();
                mBaiduMap.setMyLocationData(locationData);
                return false;
            }

            @SuppressLint("WrongConstant")
            @Override
            public void onMapClick(LatLng arg0) {
                // TODO Auto-generated method stub
                longitude = arg0.longitude;
                lareplacedude = arg0.lareplacedude;
                // 小数位数太长,只显示一部分(上传的位置还是真实经纬度)
                String str_longitude = subStringForLocation(String.valueOf(longitude));
                String str_lareplacedude = subStringForLocation(String.valueOf(lareplacedude));
                tv_longitude.setText(str_longitude);
                tv_lareplacedude.setText(str_lareplacedude);
                MyLocationData.Builder locationBuilder = new MyLocationData.Builder();
                locationBuilder.lareplacedude(lareplacedude);
                locationBuilder.longitude(longitude);
                MyLocationData locationData = locationBuilder.build();
                mBaiduMap.setMyLocationData(locationData);
                GeoCoder geoCoder = GeoCoder.newInstance();
                geoCoder.setOnGetGeoCodeResultListener(new OnGetGeoCoderResultListener() {

                    @Override
                    public void onGetGeoCodeResult(GeoCodeResult geoCodeResult) {
                    }

                    @Override
                    public void onGetReverseGeoCodeResult(ReverseGeoCodeResult reverseGeoCodeResult) {
                        if (reverseGeoCodeResult == null || reverseGeoCodeResult.error != SearchResult.ERRORNO.NO_ERROR) {
                            return;
                        }
                        address = reverseGeoCodeResult.getAddress();
                        tv_address.setText(address);
                    }
                });
                // 反向地理解析
                geoCoder.reverseGeoCode(new ReverseGeoCodeOption().location(arg0));
            }
        });
    }

    /**
     * 截取字符串,长度大于10则截取10位
     *
     * @param location
     * @return
     */
    private String subStringForLocation(String location) {
        String rt_location = "";
        if (location != null) {
            if (location.length() > 10) {
                rt_location = location.substring(0, 10);
            } else {
                rt_location = location;
            }
        }
        return rt_location;
    }

    private void initMap() {
        mBaiduMap = mMapView.getMap();
        mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL);
        // 开启定位图层
        mBaiduMap.setMyLocationEnabled(true);
    }

    private void initLocation() {
        // 利用LocationClientOption类配置定位SDK参数
        option = new LocationClientOption();
        option.setLocationMode(LocationMode.Hight_Accuracy);
        // 可选,设置定位模式,默认高精度
        // LocationMode.Hight_Accuracy:高精度;
        // LocationMode. Battery_Saving:低功耗;
        // LocationMode. Device_Sensors:仅使用设备;
        option.setCoorType("bd09ll");
        // 可选,设置返回经纬度坐标类型,默认gcj02
        // gcj02:国测局坐标;
        // bd09ll:百度经纬度坐标;
        // bd09:百度墨卡托坐标;
        // 海外地区定位,无需设置坐标类型,统一返回wgs84类型坐标
        option.setOpenGps(true);
        // 可选,设置是否使用gps,默认false
        // 使用高精度和仅用设备两种定位模式的,参数必须设置为true
        option.setLocationNotify(true);
        // 可选,设置是否当GPS有效时按照1S/1次频率输出GPS结果,默认false
        option.setIgnoreKillProcess(true);
        // 可选,定位SDK内部是一个service,并放到了独立进程。
        // 设置是否在stop的时候杀死这个进程,默认(建议)不杀死,即setIgnoreKillProcess(true)
        option.SetIgnoreCacheException(false);
        // 可选,设置是否收集Crash信息,默认收集,即参数为false
        option.setEnableSimulateGps(false);
        // 可选,设置是否需要过滤GPS仿真结果,默认需要,即参数为false
        option.setIsNeedLocationDescribe(true);
        // 可选,是否需要位置描述信息,默认为不需要,即参数为false
        // 如果开发者需要获得当前点的位置信息,此处必须为true
        option.setIsNeedLocationPoiList(true);
        // 可选,是否需要周边POI信息,默认为不需要,即参数为false
        // 如果开发者需要获得周边POI信息,此处必须为true
        // 获取详细信息
        option.setIsNeedAddress(true);
        mLocationClient.setLocOption(option);
    // mLocationClient为第二步初始化过的LocationClient对象
    // 需将配置好的LocationClientOption对象,通过setLocOption方法传递给LocationClient对象使用
    // 更多LocationClientOption的配置,请参照类参考中LocationClientOption类的详细说明
    }

    private void navigateTo(BDLocation location) {
        longitude = location.getLongitude();
        lareplacedude = location.getLareplacedude();
        tv_longitude.setText(longitude + "");
        tv_lareplacedude.setText(lareplacedude + "");
        address = location.getAddrStr();
        tv_address.setText(address);
        if (isFirstLocation) {
            latLng = new LatLng(lareplacedude, longitude);
            MapStatus.Builder builder = new MapStatus.Builder();
            MapStatus mapStatus = builder.target(latLng).zoom(15.0f).build();
            mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(mapStatus));
            isFirstLocation = false;
        }
        MyLocationData.Builder locationBuilder = new MyLocationData.Builder();
        locationBuilder.lareplacedude(location.getLareplacedude());
        locationBuilder.longitude(location.getLongitude());
        MyLocationData locationData = locationBuilder.build();
        mBaiduMap.setMyLocationData(locationData);
    }

    @Override
    public void onClick(View v) {
        switch(v.getId()) {
            case R.id.back_lay:
                Intent intent = new Intent();
                intent.putExtra("longitude", longitude);
                intent.putExtra("lareplacedude", lareplacedude);
                intent.putExtra("address", address);
                setResult(RESULT_OK, intent);
                finish();
                break;
            case R.id.custom_made:
                Intent intent2 = new Intent();
                intent2.putExtra("longitude", longitude);
                intent2.putExtra("lareplacedude", lareplacedude);
                intent2.putExtra("address", address);
                setResult(RESULT_OK, intent2);
                finish();
                break;
            default:
                break;
        }
    }

    public clreplaced MyLocationListener implements BDLocationListener {

        @Override
        public void onReceiveLocation(BDLocation arg0) {
            if (arg0.getLocType() == BDLocation.TypeGpsLocation || arg0.getLocType() == BDLocation.TypeNetWorkLocation) {
                navigateTo(arg0);
            }
        }
    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        mMapView.onResume();
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        mMapView.onPause();
    }

    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
        mMapView.onDestroy();
        // 当不需要定位图层时关闭定位图层
        mBaiduMap.setMyLocationEnabled(false);
        // 取消监听函数
        if (mLocationClient != null) {
            mLocationClient.unRegisterLocationListener(myListener);
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // 如果是返回键
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
            Intent intent = new Intent();
            intent.putExtra("longitude", longitude);
            intent.putExtra("lareplacedude", lareplacedude);
            intent.putExtra("address", address);
            setResult(RESULT_OK, intent);
            finish();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}

16 Source : RunningActivity.java
with Apache License 2.0
from SailFlorve

private void initLocation(int time) {
    LocationClientOption option = new LocationClientOption();
    option.setScanSpan(time);
    option.setOpenGps(true);
    option.setCoorType("bd09ll");
    client.setLocOption(option);
}

16 Source : BDLocationUtil.java
with Apache License 2.0
from liying2008

/**
 * 获取LocationClient配置
 * @return
 */
public static LocationClientOption getLocationClientOption() {
    LocationClientOption option = new LocationClientOption();
    // 可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
    option.setLocationMode(LocationClientOption.LocationMode.Battery_Saving);
    // 可选,默认gcj02,设置返回的定位结果坐标系
    option.setCoorType("bd09ll");
    // 可选,默认0,即仅定位一次,设置发起定位请求的间隔需要大于等于1000ms才是有效的
    int span = 1000;
    option.setScanSpan(span);
    // 可选,设置是否需要地址信息,默认不需要
    option.setIsNeedAddress(true);
    // 可选,默认false,设置是否使用gps
    option.setOpenGps(true);
    // 可选,默认false,设置是否当GPS有效时按照1S/1次频率输出GPS结果
    option.setLocationNotify(true);
    // 可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近”
    option.setIsNeedLocationDescribe(true);
    // 可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到
    option.setIsNeedLocationPoiList(true);
    // 可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死
    option.setIgnoreKillProcess(false);
    // 可选,默认false,设置是否收集CRASH信息,默认收集
    option.SetIgnoreCacheException(false);
    // 可选,默认false,设置是否需要过滤GPS仿真结果,默认需要
    option.setEnableSimulateGps(false);
    return option;
}

16 Source : NearPeopleActivity.java
with Apache License 2.0
from librahfacebook

private void initLocation() {
    LocationClientOption option = new LocationClientOption();
    option.setScanSpan(5000);
    option.setIsNeedAddress(true);
    option.setIsNeedLocationDescribe(true);
    option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
    locationClient.setLocOption(option);
}

16 Source : MainActivity.java
with Apache License 2.0
from lentitude

@Override
public void initData() {
    String cityName = getIntent().getStringExtra("cityName");
    if (!TextUtils.isEmpty(cityName)) {
        requestWeather(cityName);
    } else {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        // weather 保存API 返回的字符串
        String weatherString = prefs.getString("weatherResponse", null);
        if (weatherString != null) {
            // 有缓存时直接解析天气数据
            Weather weather = Utility.handleWeatherResponse(weatherString);
            showWeatherInfo(weather);
            mainLayout.setVisibility(View.VISIBLE);
        } else {
            // 无缓存时向服务器查询数据
            if (getNetworkInfo() != null && getNetworkInfo().isAvailable()) {
                // 查询完之后显示 coordinatorLayout.setVisibility(View.VISIBLE);
                LocationClientOption option = new LocationClientOption();
                option.setIsNeedAddress(true);
                mlocationClient.setLocOption(option);
                mlocationClient.start();
            } else {
                showDialog(null, "当前无网络,请打开网络", SIGN_NO_INTERNET);
            }
        }
        Intent intent = new Intent(MainActivity.this, AutoUpdateService.clreplaced);
        startService(intent);
    }
}

16 Source : Location.java
with GNU General Public License v3.0
from JamesLiAndroid

private void setLocationOption() {
    LocationClientOption option = new LocationClientOption();
    option.setOpenGps(true);
    option.setCoorType(COORD_TYPE_BD09LL);
    option.setServiceName("com.baidu.location.service_v2.9");
    // option.setIsNeedLocationPoiList(true);
    option.setAddrType("all");
    option.setProdName("tylbd");
    option.setPriority(2);
    option.setPoiNumber(100);
    option.disableCache(true);
    mLocationClient.setLocOption(option);
}

15 Source : MainActivity.java
with Apache License 2.0
from yangxch

public clreplaced MainActivity extends AppCompatActivity implements OnGetPoiSearchResultListener {

    private static String TAG = "MainActivity";

    private Context mContext;

    private TextView tv_city;

    private EditText et_keyword;

    private ListView lv_searchAddress, lv_poiSearch;

    private LinearLayout ll_poiSearch, ll_mapView;

    // 地图定位
    private MapView mMapView = null;

    private BaiduMap mBaiduMap = null;

    private MyLocationListener myListener = new MyLocationListener();

    public LocationClient mLocationClient = null;

    private LocationClientOption option = null;

    private boolean isFirstLocation = true;

    // 当前所在位置
    private LatLng currentLatLng;

    // 地图标注
    private Marker marker;

    // poi检索
    // 反向地理解析,获取周边poi
    private GeoCoder mGeoCoder;

    private PoiSearch mPoiSearch = null;

    // 地点检索输入提示检索(Sug检索)
    private SuggestionSearch mSuggestionSearch = null;

    // 地图中心点坐标
    private LatLng center;

    // poi检索半径
    private int radius = 300;

    // 分页页码(分页功能我就不写了,常用的东西,你们自个加吧)
    private int loadIndex = 0;

    private int pageSize = 50;

    // 地理反向解析获取的poi
    private List<PoiInfo> poiInfoListForGeoCoder = new ArrayList<>();

    // 检索结果集合
    private List<PoiInfo> poiInfoListForSearch = new ArrayList<>();

    private Adapter_SearchAddress adapter_searchAddress;

    private String cityName = "";

    private String keyword = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getSupportActionBar().hide();
        setContentView(R.layout.activity_main);
        mContext = MainActivity.this;
        tv_city = findViewById(R.id.tv_city);
        et_keyword = findViewById(R.id.et_keyword);
        ll_mapView = findViewById(R.id.ll_mapView);
        ll_poiSearch = findViewById(R.id.ll_poiSearch);
        lv_searchAddress = findViewById(R.id.lv_searchAddress);
        lv_poiSearch = findViewById(R.id.lv_poiSearch);
        // 监听输入框
        monitorEditTextChage();
        // 初始化地理解析、建议搜索、poi搜索
        initGeoCoder();
        initSuggestionSearch();
        initPoiSearch();
        // 初始化地图及定位
        initMap();
        initLocation();
        // 监听地图事件(加载完成、拖动等)
        monitorMap();
    }

    private void monitorEditTextChage() {
        et_keyword.addTextChangedListener(new Texreplacedcher() {

            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                keyword = editable.toString();
                if (keyword.length() <= 0) {
                    // 当清空文本后展示地图,隐藏搜索结果
                    showMapView();
                    return;
                }
                /* 使用建议搜索服务获取建议列表,结果在onSuggestionResult()中更新 */
                /* 由于我们需要滑动地图展示周边poi,所以就不用建议搜索列表来搜索poi了,搜索时直接利用城市和输入的关键字进行城市内检索poi */
                // mSuggestionSearch.requestSuggestion((new SuggestionSearchOption())
                // .keyword(keyword)
                // .city(cityName));
                searchCityPoiAddress();
            }
        });
    }

    private void initMap() {
        mMapView = (MapView) findViewById(R.id.bmapView);
        mBaiduMap = mMapView.getMap();
        mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL);
        // 开启定位图层
        mBaiduMap.setMyLocationEnabled(true);
    }

    /**
     * 初始化定位相关
     */
    private void initLocation() {
        // 声明LocationClient类
        mLocationClient = new LocationClient(getApplicationContext());
        // 利用LocationClientOption类配置定位SDK参数
        option = new LocationClientOption();
        option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
        // 可选,设置定位模式,默认高精度  LocationMode.Hight_Accuracy:高精度; LocationMode. Battery_Saving:低功耗; LocationMode. Device_Sensors:仅使用设备;
        option.setCoorType("bd09ll");
        // 可选,设置返回经纬度坐标类型,默认gcj02
        // gcj02:国测局坐标;
        // bd09ll:百度经纬度坐标;
        // bd09:百度墨卡托坐标;
        // 海外地区定位,无需设置坐标类型,统一返回wgs84类型坐标
        option.setOpenGps(true);
        // 可选,设置是否使用gps,默认false
        // 使用高精度和仅用设备两种定位模式的,参数必须设置为true
        option.setLocationNotify(true);
        // 可选,设置是否当GPS有效时按照1S/1次频率输出GPS结果,默认false
        option.setIgnoreKillProcess(true);
        // 可选,定位SDK内部是一个service,并放到了独立进程。
        // 设置是否在stop的时候杀死这个进程,默认(建议)不杀死,即setIgnoreKillProcess(true)
        option.SetIgnoreCacheException(false);
        // 可选,设置是否收集Crash信息,默认收集,即参数为false
        option.setEnableSimulateGps(false);
        // 可选,设置是否需要过滤GPS仿真结果,默认需要,即参数为false
        option.setIsNeedLocationDescribe(true);
        // 可选,是否需要位置描述信息,默认为不需要,即参数为false
        option.setIsNeedLocationPoiList(true);
        // 可选,是否需要周边POI信息,默认为不需要,即参数为false
        // 获取详细信息
        option.setIsNeedAddress(true);
        // 设置扫描间隔
        // option.setScanSpan(10000);
        mLocationClient.setLocOption(option);
        // 注册监听函数
        mLocationClient.registerLocationListener(myListener);
        mLocationClient.start();
    }

    /**
     * 根据获取到的位置在地图上移动“我”的位置
     *
     * @param location
     */
    private void navigateTo(BDLocation location) {
        double longitude = location.getLongitude();
        double lareplacedude = location.getLareplacedude();
        String address = location.getAddrStr();
        if (isFirstLocation) {
            currentLatLng = new LatLng(lareplacedude, longitude);
            MapStatus.Builder builder = new MapStatus.Builder();
            MapStatus mapStatus = builder.target(currentLatLng).zoom(17.0f).build();
            mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(mapStatus));
            isFirstLocation = false;
            // 反向地理解析(含有poi列表)
            mGeoCoder.reverseGeoCode(new ReverseGeoCodeOption().location(currentLatLng));
        }
        MyLocationData.Builder locationBuilder = new MyLocationData.Builder();
        locationBuilder.lareplacedude(location.getLareplacedude());
        locationBuilder.longitude(location.getLongitude());
        MyLocationData locationData = locationBuilder.build();
        mBaiduMap.setMyLocationData(locationData);
    }

    /**
     * 监听当前位置
     */
    public clreplaced MyLocationListener extends BDAbstractLocationListener {

        @Override
        public void onReceiveLocation(BDLocation location) {
            // mapView 销毁后不在处理新接收的位置
            if (location == null || mMapView == null) {
                return;
            }
            Log.e(TAG, "当前“我”的位置:" + location.getAddrStr());
            if (location.getLocType() == BDLocation.TypeGpsLocation || location.getLocType() == BDLocation.TypeNetWorkLocation) {
                navigateTo(location);
                cityName = location.getCity();
                tv_city.setText(cityName);
                Log.e(TAG, "当前定位城市:" + location.getCity());
            }
        }
    }

    /**
     * 监听地图事件(这里主要监听移动地图)
     */
    private void monitorMap() {
        mBaiduMap.setOnMapLoadedCallback(new BaiduMap.OnMapLoadedCallback() {

            @Override
            public void onMapLoaded() {
            // TODO Auto-generated method stub
            // 地图加载完成
            }
        });
        mBaiduMap.setOnMapStatusChangeListener(new BaiduMap.OnMapStatusChangeListener() {

            /**
             * 手势操作地图,设置地图状态等操作导致地图状态开始改变。
             * @param mapStatus 地图状态改变开始时的地图状态
             */
            @Override
            public void onMapStatusChangeStart(MapStatus mapStatus) {
            }

            /**
             * 因某种操作导致地图状态开始改变。
             * @param mapStatus 地图状态改变开始时的地图状态
             * @param i 取值有:
             * 1:用户手势触发导致的地图状态改变,比如双击、拖拽、滑动底图
             * 2:SDK导致的地图状态改变, 比如点击缩放控件、指南针图标
             * 3:开发者调用,导致的地图状态改变
             */
            @Override
            public void onMapStatusChangeStart(MapStatus mapStatus, int i) {
                Log.e(TAG, "地图状态改变开始时:" + i + "");
            }

            /**
             * 地图状态变化中
             * @param mapStatus 当前地图状态
             */
            @Override
            public void onMapStatusChange(MapStatus mapStatus) {
                LatLng latlng = mBaiduMap.getMapStatus().target;
                double lareplacedude = latlng.lareplacedude;
                double longitude = latlng.longitude;
                // Log.e(TAG, "地图状态变化中:" + lareplacedude + "," + longitude);
                addMarker(latlng);
            }

            /**
             * 地图状态改变结束
             * @param mapStatus 地图状态改变结束后的地图状态
             */
            @Override
            public void onMapStatusChangeFinish(MapStatus mapStatus) {
                center = mBaiduMap.getMapStatus().target;
                // Log.e(TAG, "地图状态改变结束后:" + center.lareplacedude + "," + center.longitude);
                if (poiInfoListForGeoCoder != null) {
                    poiInfoListForGeoCoder.clear();
                }
                // 反向地理解析(含有poi列表)
                mGeoCoder.reverseGeoCode(new ReverseGeoCodeOption().location(center));
            }
        });
    }

    /**
     * 添加marker
     *
     * @param point Marker坐标点
     */
    private void addMarker(LatLng point) {
        if (marker != null) {
            // marker.remove();
            marker.setPosition(point);
        } else {
            // 构建Marker图标
            BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.mipmap.location);
            // 构建MarkerOption,用于在地图上添加Marker
            OverlayOptions option = new MarkerOptions().position(point).icon(bitmap);
            // 在地图上添加Marker,并显示
            marker = (Marker) mBaiduMap.addOverlay(option);
        }
    }

    /**
     * 展示搜索的布局
     */
    private void showSeachView() {
        ll_mapView.setVisibility(View.GONE);
        ll_poiSearch.setVisibility(View.VISIBLE);
    }

    /**
     * 展示地图的布局
     */
    private void showMapView() {
        ll_mapView.setVisibility(View.VISIBLE);
        ll_poiSearch.setVisibility(View.GONE);
    }

    // -----------------------------------------反向地理解析,获取周边poi列表--------------------------------------------------
    /**
     * 反向地理解析,结果中含有poi信息,用于刚进入地图和移动地图时使用
     */
    private void initGeoCoder() {
        mGeoCoder = GeoCoder.newInstance();
        mGeoCoder.setOnGetGeoCodeResultListener(new OnGetGeoCoderResultListener() {

            @Override
            public void onGetGeoCodeResult(GeoCodeResult geoCodeResult) {
            }

            @Override
            public void onGetReverseGeoCodeResult(ReverseGeoCodeResult reverseGeoCodeResult) {
                if (poiInfoListForGeoCoder != null) {
                    poiInfoListForGeoCoder.clear();
                }
                if (reverseGeoCodeResult.error.equals(SearchResult.ERRORNO.NO_ERROR)) {
                    // 获取城市
                    ReverseGeoCodeResult.AddressComponent addressComponent = reverseGeoCodeResult.getAddressDetail();
                    cityName = addressComponent.city;
                    tv_city.setText(cityName);
                    // 获取poi列表
                    if (reverseGeoCodeResult.getPoiList() != null) {
                        poiInfoListForGeoCoder = reverseGeoCodeResult.getPoiList();
                    }
                } else {
                    Toast.makeText(mContext, "该位置范围内无信息", Toast.LENGTH_SHORT);
                }
                initGeoCoderListView();
            }
        });
    }

    // -----------------------------------------建议搜索(sug检索)------------------------------------------------------------------
    private void initSuggestionSearch() {
        // 初始化建议搜索模块,注册建议搜索事件监听(sug搜索)
        mSuggestionSearch = SuggestionSearch.newInstance();
        mSuggestionSearch.setOnGetSuggestionResultListener(new OnGetSuggestionResultListener() {

            /**
             * 获取在线建议搜索结果,得到requestSuggestion返回的搜索结果
             * @param suggestionResult    Sug检索结果
             */
            @Override
            public void onGetSuggestionResult(SuggestionResult suggestionResult) {
                if (suggestionResult == null || suggestionResult.getAllSuggestions() == null) {
                    Toast.makeText(mContext, "未找到结果", Toast.LENGTH_LONG).show();
                    return;
                }
                List<SuggestionResult.SuggestionInfo> sugList = suggestionResult.getAllSuggestions();
                for (SuggestionResult.SuggestionInfo info : sugList) {
                    if (info.key != null) {
                        Log.e(TAG, "搜索结果:" + info.toString());
                        Log.e(TAG, "key:" + info.key);
                        DecimalFormat df = new DecimalFormat("######0");
                        // 用当前所在位置算出距离
                        String distance = df.format(DistanceUtil.getDistance(currentLatLng, info.pt));
                        Log.e(TAG, "距离:" + distance);
                    }
                }
            }
        });
    }

    // --------------------------------------------------poi检索---------------------------------------------------------------------
    private void initPoiSearch() {
        // 初始化搜索模块,注册搜索事件监听
        mPoiSearch = PoiSearch.newInstance();
        mPoiSearch.setOnGetPoiSearchResultListener(this);
    }

    /**
     * 获取POI搜索结果,包括searchInCity,searchNearby,searchInBound返回的搜索结果
     *
     * @param poiResult Poi检索结果,包括城市检索,周边检索,区域检索
     */
    @Override
    public void onGetPoiResult(PoiResult poiResult) {
        if (poiInfoListForSearch != null) {
            poiInfoListForSearch.clear();
        }
        if (poiResult == null || poiResult.error == SearchResult.ERRORNO.RESULT_NOT_FOUND) {
            Toast.makeText(mContext, "未找到结果", Toast.LENGTH_LONG).show();
            initPoiSearchListView();
            return;
        }
        if (poiResult.error == SearchResult.ERRORNO.NO_ERROR) {
            poiInfoListForSearch = poiResult.getAllPoi();
            showSeachView();
            initPoiSearchListView();
            return;
        }
        if (poiResult.error == SearchResult.ERRORNO.AMBIGUOUS_KEYWORD) {
            // 当输入关键字在本市没有找到,但在其他城市找到时,返回包含该关键字信息的城市列表
            String strInfo = "在";
            for (CityInfo cityInfo : poiResult.getSuggestCityList()) {
                strInfo += cityInfo.city;
                strInfo += ",";
            }
            strInfo += "找到结果";
            Toast.makeText(mContext, strInfo, Toast.LENGTH_LONG).show();
        }
    }

    /**
     * 获取POI详情搜索结果,得到searchPoiDetail返回的搜索结果
     * V5.2.0版本之后,该方法废弃,使用{@link #onGetPoiDetailResult(PoiDetailSearchResult)}代替
     *
     * @param poiDetailResult POI详情检索结果
     */
    @Override
    public void onGetPoiDetailResult(PoiDetailResult poiDetailResult) {
        if (poiDetailResult.error != SearchResult.ERRORNO.NO_ERROR) {
            Toast.makeText(mContext, "抱歉,未找到结果", Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(mContext, poiDetailResult.getName() + ": " + poiDetailResult.getAddress(), Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onGetPoiDetailResult(PoiDetailSearchResult poiDetailSearchResult) {
        if (poiDetailSearchResult.error != SearchResult.ERRORNO.NO_ERROR) {
            Toast.makeText(mContext, "抱歉,未找到结果", Toast.LENGTH_SHORT).show();
        } else {
            List<PoiDetailInfo> poiDetailInfoList = poiDetailSearchResult.getPoiDetailInfoList();
            if (null == poiDetailInfoList || poiDetailInfoList.isEmpty()) {
                Toast.makeText(mContext, "抱歉,检索结果为空", Toast.LENGTH_SHORT).show();
                return;
            }
            for (int i = 0; i < poiDetailInfoList.size(); i++) {
                PoiDetailInfo poiDetailInfo = poiDetailInfoList.get(i);
                if (null != poiDetailInfo) {
                    Toast.makeText(mContext, poiDetailInfo.getName() + ": " + poiDetailInfo.getAddress(), Toast.LENGTH_SHORT).show();
                }
            }
        }
    }

    @Override
    public void onGetPoiIndoorResult(PoiIndoorResult poiIndoorResult) {
    }

    private void initGeoCoderListView() {
        adapter_searchAddress = new Adapter_SearchAddress(poiInfoListForGeoCoder, mContext, currentLatLng);
        lv_searchAddress.setAdapter(adapter_searchAddress);
    }

    private void initPoiSearchListView() {
        adapter_searchAddress = new Adapter_SearchAddress(poiInfoListForSearch, mContext, currentLatLng);
        lv_poiSearch.setAdapter(adapter_searchAddress);
    }

    /**
     * 周边搜索
     */
    private void searchNearbyProcess(LatLng center) {
        // 以定位点为中心,搜索半径以内的
        PoiNearbySearchOption nearbySearchOption = new PoiNearbySearchOption().keyword(keyword).sortType(PoiSortType.distance_from_near_to_far).location(center).radius(radius).pageCapacity(pageSize).pageNum(loadIndex);
        mPoiSearch.searchNearby(nearbySearchOption);
    }

    /**
     * 响应城市内搜索
     */
    public void searchCityPoiAddress() {
        mPoiSearch.searchInCity((new PoiCitySearchOption()).city(cityName).keyword(// 必填
        keyword).pageCapacity(pageSize).pageNum(// 分页页码
        loadIndex));
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
            // 重写返回键
            if (keyword.trim().length() > 0) {
                // 如果输入框还有字,就返回到地图界面并清空输入框
                showMapView();
                et_keyword.setText("");
            } else {
                finish();
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    protected void onResume() {
        super.onResume();
        mMapView.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        mMapView.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mMapView.onDestroy();
        // 当不需要定位图层时关闭定位图层
        mBaiduMap.setMyLocationEnabled(false);
        // 取消监听函数
        if (mLocationClient != null) {
            mLocationClient.unRegisterLocationListener(myListener);
        }
        mPoiSearch.destroy();
        mSuggestionSearch.destroy();
        mGeoCoder.destroy();
    }
}

14 Source : AddressEditDelegate.java
with MIT License
from zion223

public clreplaced AddressEditDelegate extends LatteDelegate implements OnGetPoiSearchResultListener {

    private static final String TAG = "AddressEditDelegate";

    @BindView(R2.id.btn_address_edit_save)
    AppCompatButton mBtnSave;

    @BindView(R2.id.edit_address_edit_name)
    ClearEditText mAddressName;

    @BindView(R2.id.edit_address_edit_phone)
    ClearEditText mAddressPhone;

    @BindView(R2.id.tv_address_edit_house_number)
    ClearEditText mAddressHouseNumber;

    @BindView(R2.id.mv_address_edit_map)
    MapView mMapView;

    @BindView(R2.id.btn_address_edit_delete)
    TextView mTvDeleteAddress;

    @BindView(R2.id.tv_address_edit)
    TextView mTvEditAddress;

    @BindView(R2.id.cv_address_edit_bottom)
    CardView mCardViewBottom;

    @BindView(R2.id.cv_address_edit_top)
    CardView mCardViewTop;

    @BindView(R2.id.ll_address_edit_input)
    LinearLayout mLlInputText;

    @BindView(R2.id.tv_address_edit_city)
    TextView mTvCurrrentCity;

    @BindView(R2.id.et_address_edit_keyword)
    EditText mEtSearchKeyword;

    @BindView(R2.id.lv_address_edit_search)
    RecyclerView mLvSearchAddress;

    @BindView(R2.id.cv_address_edit_search)
    CardView mCardViewSearchAddress;

    @BindView(R2.id.lv_address_edit_poiSearch)
    RecyclerView mLvPoiSearchAddress;

    @BindView(R2.id.ll_address_edit_poisearch)
    LinearLayout mLlPoiSearchAddress;

    @BindView(R2.id.tv_address_edit_detail_pre)
    TextView mTvAddressPrefix;

    @BindView(R2.id.tv_address_edit_detail_suf)
    TextView mTvAddressSuffix;

    @BindView(R2.id.radioBtn_address_edit_male)
    RadioButton mRadioBtnMale;

    @BindView(R2.id.radioBtn_address_edit_female)
    RadioButton mRadioBtnFemale;

    @BindView(R2.id.tv_address_edit_company_tag)
    TextView mTvCompanyTag;

    @BindView(R2.id.tv_address_edit_school_tag)
    TextView mTvSchoolTag;

    @BindView(R2.id.tv_address_edit_home_tag)
    TextView mTvHomeTag;

    private String addressPre = null;

    private String addressSuf = null;

    private String houseNumber = null;

    private Integer tag = null;

    private String name = null;

    private Integer gender = null;

    private String phone = null;

    // 标签
    Drawable address_tag_border;

    Drawable address_tag_border_choosed;

    // 地图定位
    private BaiduMap mBaiduMap;

    private MyLocationListener myListener = new MyLocationListener();

    public LocationClient mLocationClient = null;

    private LocationClientOption option = null;

    private boolean isFirstLocation = true;

    // 当前所在位置
    private LatLng currentLatLng;

    // 地图标注
    private Marker marker;

    // poi检索
    // 反向地理解析,获取周边poi
    private GeoCoder mGeoCoder;

    private PoiSearch mPoiSearch = null;

    // 地点检索输入提示检索(Sug检索)
    private SuggestionSearch mSuggestionSearch = null;

    // 地图中心点坐标
    private LatLng center;

    // poi检索半径
    private int radius = 300;

    // 分页页码(分页功能我就不写了,常用的东西,你们自个加吧)
    private int loadIndex = 0;

    private int pageSize = 50;

    // 地理反向解析获取的poi
    private List<PoiInfo> poiInfoListForGeoCoder = new ArrayList<>();

    // 检索结果集合
    private List<PoiInfo> poiInfoListForSearch = new ArrayList<>();

    private SearchAddressAdapter mSearchAddressAdapter;

    private String cityName = "";

    private String keyword = "";

    private static final String NAME = "NAME";

    private static final String PHONE = "PHONE";

    private static final String PREFIX_ADDRESS = "PREFIX_ADDRESS";

    private static final String SUFFIX_ADDRESS = "SUFFIX_ADDRESS";

    private static final String HOUSE_NUMBER = "HOUSE_NUMBER";

    private static final String ADDRESS_TAG = "ADDRESS_TAG";

    private static final String GENDER = "GENDER";

    private static final Integer HOME_TAG = 0;

    private static final Integer SCHOOL_TAG = 1;

    private static final Integer COMPANY_TAG = 2;

    private UiSettings mUiSettings;

    public static AddressEditDelegate create(String houseNumber, String name, String phone, String addressPre, String addressSuf, Integer tag, Integer gender) {
        final Bundle args = new Bundle();
        args.putString(NAME, name);
        args.putString(PHONE, phone);
        args.putString(PREFIX_ADDRESS, addressPre);
        args.putString(SUFFIX_ADDRESS, addressSuf);
        args.putString(HOUSE_NUMBER, houseNumber);
        args.putInt(ADDRESS_TAG, tag);
        args.putInt(GENDER, gender);
        final AddressEditDelegate delegate = new AddressEditDelegate();
        delegate.setArguments(args);
        return delegate;
    }

    /**
     * 地址前缀 addressPre  e.g.青岛国际动漫游戏产业园
     * 地址后缀 addressSuf  e.g.青岛市市南区
     * 门牌号  housenNumber e.g.9栋301
     * 标签    tag
     * 联系人  name
     * 手机号  phone
     * 性别 先生、女士 gender
     */
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final Bundle args = getArguments();
        if (args != null) {
            name = args.getString(NAME);
            phone = args.getString(PHONE);
            houseNumber = args.getString(HOUSE_NUMBER);
            addressPre = args.getString(PREFIX_ADDRESS);
            addressSuf = args.getString(SUFFIX_ADDRESS);
            gender = args.getInt(GENDER);
            tag = args.getInt(ADDRESS_TAG);
        } else {
            throw new NullPointerException("Bundle is null");
        }
    }

    @Override
    public Object setLayout() {
        return R.layout.delegate_address_edit;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, @NonNull View view) {
        final MapStatus.Builder builder = new MapStatus.Builder();
        builder.zoom(18.0f);
        // 监听输入框
        monitorEditTextChage();
        initGeoCoder();
        initPoiSearch();
        initSuggestionSearch();
        initMap();
        initLocation();
        monitorMap();
        // final LatLng GEO_CHONGQING = new LatLng(29.5924475600, 106.4984776500);
        // MapStatusUpdate status1  = MapStatusUpdateFactory.newLatLng(GEO_CHONGQING);
        // mBaiduMap.setMapStatus(status1);
        // mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL);
        // 姓名
        mAddressName.setText(name);
        // 手机号
        mAddressPhone.setText(phone);
        // 门牌号
        mAddressHouseNumber.setText(houseNumber);
        // 地址前缀
        mTvAddressPrefix.setText(addressPre);
        // 地址后缀
        mTvAddressSuffix.setText(addressSuf);
        // 性别
        if (gender == 0) {
            mRadioBtnMale.setChecked(true);
        } else {
            mRadioBtnFemale.setChecked(true);
        }
        // 地址标签 0:home 1:school 2:company
        if (tag.equals(HOME_TAG)) {
            mTvHomeTag.setBackground(getResources().getDrawable(R.drawable.address_tag_border_choosed));
        } else if (tag.equals(SCHOOL_TAG)) {
            mTvSchoolTag.setBackground(getResources().getDrawable(R.drawable.address_tag_border_choosed));
        } else if (tag.equals(COMPANY_TAG)) {
            mTvCompanyTag.setBackground(getResources().getDrawable(R.drawable.address_tag_border_choosed));
        }
        address_tag_border = getResources().getDrawable(R.drawable.address_tag_border);
        address_tag_border_choosed = getResources().getDrawable(R.drawable.address_tag_border_choosed);
    }

    /**
     * 监听地图事件(这里主要监听移动地图)
     */
    private void monitorMap() {
        mBaiduMap.setOnMapLoadedCallback(new BaiduMap.OnMapLoadedCallback() {

            @Override
            public void onMapLoaded() {
            // 地图加载完成
            }
        });
        mBaiduMap.setOnMapStatusChangeListener(new BaiduMap.OnMapStatusChangeListener() {

            /**
             * 手势操作地图,设置地图状态等操作导致地图状态开始改变。
             * @param mapStatus 地图状态改变开始时的地图状态
             */
            @Override
            public void onMapStatusChangeStart(MapStatus mapStatus) {
            }

            /**
             * 因某种操作导致地图状态开始改变。
             * @param mapStatus 地图状态改变开始时的地图状态
             * @param i 取值有:
             * 1:用户手势触发导致的地图状态改变,比如双击、拖拽、滑动底图
             * 2:SDK导致的地图状态改变, 比如点击缩放控件、指南针图标
             * 3:开发者调用,导致的地图状态改变
             */
            @Override
            public void onMapStatusChangeStart(MapStatus mapStatus, int i) {
                Log.e(TAG, "地图状态改变开始时:" + i + "");
            }

            /**
             * 地图状态变化中
             * @param mapStatus 当前地图状态
             */
            @Override
            public void onMapStatusChange(MapStatus mapStatus) {
                LatLng latlng = mBaiduMap.getMapStatus().target;
                double lareplacedude = latlng.lareplacedude;
                double longitude = latlng.longitude;
                Log.e(TAG, "地图状态变化中:" + lareplacedude + "," + longitude);
                addMarker(latlng);
            }

            /**
             * 地图状态改变结束
             * @param mapStatus 地图状态改变结束后的地图状态
             */
            @Override
            public void onMapStatusChangeFinish(MapStatus mapStatus) {
                center = mBaiduMap.getMapStatus().target;
                // Log.e(TAG, "地图状态改变结束后:" + center.lareplacedude + "," + center.longitude);
                if (poiInfoListForGeoCoder != null) {
                    poiInfoListForGeoCoder.clear();
                }
                // 反向地理解析(含有poi列表)
                mGeoCoder.reverseGeoCode(new ReverseGeoCodeOption().location(center));
            }
        });
    }

    /**
     * 添加marker
     *
     * @param point Marker坐标点
     */
    private void addMarker(LatLng point) {
        if (marker != null) {
            // marker.remove();
            marker.setPosition(point);
        } else {
            // 构建Marker图标
            BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.drawable.address_edit_tag);
            // 构建MarkerOption,用于在地图上添加Marker
            OverlayOptions option = new MarkerOptions().position(point).icon(bitmap);
            // 在地图上添加Marker,并显示
            marker = (Marker) mBaiduMap.addOverlay(option);
        }
    }

    private void initPoiSearch() {
        // 初始化搜索模块,注册搜索事件监听
        mPoiSearch = PoiSearch.newInstance();
        mPoiSearch.setOnGetPoiSearchResultListener(this);
    }

    // -----------------------------------------建议搜索(sug检索)------------------------------------------------------------------
    private void initSuggestionSearch() {
        // 初始化建议搜索模块,注册建议搜索事件监听(sug搜索)
        mSuggestionSearch = SuggestionSearch.newInstance();
        mSuggestionSearch.setOnGetSuggestionResultListener(new OnGetSuggestionResultListener() {

            /**
             * 获取在线建议搜索结果,得到requestSuggestion返回的搜索结果
             * @param suggestionResult    Sug检索结果
             */
            @Override
            public void onGetSuggestionResult(SuggestionResult suggestionResult) {
                if (suggestionResult == null || suggestionResult.getAllSuggestions() == null) {
                    Toast.makeText(getContext(), "未找到结果", Toast.LENGTH_LONG).show();
                    return;
                }
                List<SuggestionResult.SuggestionInfo> sugList = suggestionResult.getAllSuggestions();
                for (SuggestionResult.SuggestionInfo info : sugList) {
                    if (info.key != null) {
                        Log.e(TAG, "搜索结果:" + info.toString());
                        Log.e(TAG, "key:" + info.key);
                        DecimalFormat df = new DecimalFormat("######0");
                        // 用当前所在位置算出距离
                        String distance = df.format(DistanceUtil.getDistance(currentLatLng, info.pt));
                        Log.e(TAG, "距离:" + distance);
                    }
                }
            }
        });
    }

    private void initGeoCoder() {
        mGeoCoder = GeoCoder.newInstance();
        mGeoCoder.setOnGetGeoCodeResultListener(new OnGetGeoCoderResultListener() {

            @Override
            public void onGetGeoCodeResult(GeoCodeResult geoCodeResult) {
            }

            @Override
            public void onGetReverseGeoCodeResult(ReverseGeoCodeResult reverseGeoCodeResult) {
                if (poiInfoListForGeoCoder != null) {
                    poiInfoListForGeoCoder.clear();
                }
                if (reverseGeoCodeResult.error.equals(SearchResult.ERRORNO.NO_ERROR)) {
                    // 获取城市
                    ReverseGeoCodeResult.AddressComponent addressComponent = reverseGeoCodeResult.getAddressDetail();
                    cityName = addressComponent.city;
                    mTvCurrrentCity.setText(cityName);
                    // 获取poi列表
                    if (reverseGeoCodeResult.getPoiList() != null) {
                        poiInfoListForGeoCoder = reverseGeoCodeResult.getPoiList();
                    }
                } else {
                    Toast.makeText(getContext(), "该位置范围内无信息", Toast.LENGTH_SHORT).show();
                }
                initGeoCoderListView();
            }
        });
    }

    private void initMap() {
        mBaiduMap = mMapView.getMap();
        mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL);
        // 开启定位图层
        mBaiduMap.setMyLocationEnabled(true);
        mUiSettings = mBaiduMap.getUiSettings();
        mUiSettings.setAllGesturesEnabled(false);
    }

    private void initLocation() {
        // 声明LocationClient类
        mLocationClient = new LocationClient(getContext());
        // 利用LocationClientOption类配置定位SDK参数
        option = new LocationClientOption();
        option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
        // 可选,设置定位模式,默认高精度  LocationMode.Hight_Accuracy:高精度; LocationMode. Battery_Saving:低功耗; LocationMode. Device_Sensors:仅使用设备;
        option.setCoorType("bd09ll");
        // 可选,设置返回经纬度坐标类型,默认gcj02
        // gcj02:国测局坐标;
        // bd09ll:百度经纬度坐标;
        // bd09:百度墨卡托坐标;
        // 海外地区定位,无需设置坐标类型,统一返回wgs84类型坐标
        option.setOpenGps(true);
        // 可选,设置是否使用gps,默认false
        // 使用高精度和仅用设备两种定位模式的,参数必须设置为true
        option.setLocationNotify(true);
        // 可选,设置是否当GPS有效时按照1S/1次频率输出GPS结果,默认false
        option.setIgnoreKillProcess(true);
        // 可选,定位SDK内部是一个service,并放到了独立进程。
        // 设置是否在stop的时候杀死这个进程,默认(建议)不杀死,即setIgnoreKillProcess(true)
        option.SetIgnoreCacheException(false);
        // 可选,设置是否收集Crash信息,默认收集,即参数为false
        option.setEnableSimulateGps(false);
        // 可选,设置是否需要过滤GPS仿真结果,默认需要,即参数为false
        option.setIsNeedLocationDescribe(true);
        // 可选,是否需要位置描述信息,默认为不需要,即参数为false
        option.setIsNeedLocationPoiList(true);
        // 可选,是否需要周边POI信息,默认为不需要,即参数为false
        // 获取详细信息
        option.setIsNeedAddress(true);
        // 设置扫描间隔
        // option.setScanSpan(10000);
        mLocationClient.setLocOption(option);
        // 注册监听函数
        mLocationClient.registerLocationListener(myListener);
        mLocationClient.start();
    }

    @OnClick(R2.id.btn_address_edit_save)
    void onClickSaveAddress() {
    }

    @OnClick(R2.id.iv_address_edit_backarrow)
    void onClickReturn() {
        getSupportDelegate().pop();
    }

    @OnClick(R2.id.btn_address_edit_delete)
    void onClickDeleteAddress() {
        getSupportDelegate().pop();
    }

    @OnClick(R2.id.tv_address_edit)
    void onClickEditAddress() {
        mCardViewBottom.setAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.out_bottom));
        mCardViewTop.setAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.out_bottom));
        mCardViewBottom.setVisibility(View.GONE);
        mCardViewTop.setVisibility(View.GONE);
        mCardViewSearchAddress.setAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.in_bottom));
        mLlInputText.setVisibility(View.VISIBLE);
        mCardViewSearchAddress.setVisibility(View.VISIBLE);
        mLvSearchAddress.setVisibility(View.VISIBLE);
        mSearchAddressAdapter.notifyDataSetChanged();
        mUiSettings.setAllGesturesEnabled(true);
    }

    // 0:home 1:school 2:company
    @OnClick(R2.id.tv_address_edit_home_tag)
    void onClickChooseHomeTag() {
        if (tag.equals(HOME_TAG)) {
            mTvHomeTag.setBackground(address_tag_border);
        } else {
            tag = HOME_TAG;
            mTvHomeTag.setBackground(address_tag_border_choosed);
            mTvCompanyTag.setBackground(address_tag_border);
            mTvSchoolTag.setBackground(address_tag_border);
        }
    }

    @OnClick(R2.id.tv_address_edit_school_tag)
    void onClickChooseSchoolTag() {
        if (tag.equals(SCHOOL_TAG)) {
            mTvSchoolTag.setBackground(address_tag_border);
        } else {
            tag = SCHOOL_TAG;
            mTvSchoolTag.setBackground(address_tag_border_choosed);
            mTvHomeTag.setBackground(address_tag_border);
            mTvCompanyTag.setBackground(address_tag_border);
        }
    }

    @OnClick(R2.id.tv_address_edit_company_tag)
    void onClickChooseCompanyTag() {
        if (tag.equals(COMPANY_TAG)) {
            mTvCompanyTag.setBackground(address_tag_border);
        } else {
            tag = COMPANY_TAG;
            mTvCompanyTag.setBackground(address_tag_border_choosed);
            mTvHomeTag.setBackground(address_tag_border);
            mTvSchoolTag.setBackground(address_tag_border);
        }
    }

    @OnClick(R2.id.radioBtn_address_edit_male)
    void onClickMale() {
        if (gender != 0) {
            gender = 0;
            mRadioBtnMale.setChecked(true);
            mRadioBtnFemale.setChecked(false);
        }
    }

    @OnClick(R2.id.radioBtn_address_edit_female)
    void onClickFemale() {
        if (gender != 1) {
            gender = 1;
            mRadioBtnFemale.setChecked(true);
            mRadioBtnMale.setChecked(false);
        }
    }

    @Override
    public void onResume() {
        // 在activity执行onResume时执行mMapView. onResume (),实现地图生命周期管理
        mMapView.onResume();
        super.onResume();
    }

    @Override
    public void onPause() {
        // 在activity执行onPause时执行mMapView. onPause (),实现地图生命周期管理
        mMapView.onPause();
        super.onPause();
    }

    /**
     * 获取POI搜索结果,包括searchInCity,searchNearby,searchInBound返回的搜索结果
     *
     * @param poiResult Poi检索结果,包括城市检索,周边检索,区域检索
     */
    @Override
    public void onGetPoiResult(PoiResult poiResult) {
        if (poiInfoListForSearch != null) {
            poiInfoListForSearch.clear();
        }
        if (poiResult == null || poiResult.error == SearchResult.ERRORNO.RESULT_NOT_FOUND) {
            Toast.makeText(getContext(), "未找到结果", Toast.LENGTH_LONG).show();
            initPoiSearchListView();
            return;
        }
        if (poiResult.error == SearchResult.ERRORNO.NO_ERROR) {
            poiInfoListForSearch = poiResult.getAllPoi();
            showSeachView();
            initPoiSearchListView();
            return;
        }
        if (poiResult.error == SearchResult.ERRORNO.AMBIGUOUS_KEYWORD) {
            // 当输入关键字在本市没有找到,但在其他城市找到时,返回包含该关键字信息的城市列表
            String strInfo = "在";
            for (CityInfo cityInfo : poiResult.getSuggestCityList()) {
                strInfo += cityInfo.city;
                strInfo += ",";
            }
            strInfo += "找到结果";
            Toast.makeText(getContext(), strInfo, Toast.LENGTH_LONG).show();
        }
    }

    private void initGeoCoderListView() {
        mSearchAddressAdapter = new SearchAddressAdapter(poiInfoListForGeoCoder, currentLatLng);
        mSearchAddressAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {

            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                final PoiInfo info = (PoiInfo) adapter.gereplacedem(position);
                Collections.swap(poiInfoListForGeoCoder, 0, position);
                replacedert info != null;
                LatLng choosedLocation = info.getLocation();
                // 移动marker的位置
                if (marker != null) {
                    marker.setPosition(choosedLocation);
                }
                final MapStatusUpdate status = MapStatusUpdateFactory.newLatLng(info.getLocation());
                mBaiduMap.setMapStatus(status);
                mCardViewSearchAddress.setVisibility(View.GONE);
                mLlInputText.setVisibility(View.GONE);
                mCardViewBottom.setAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.in_bottom));
                mCardViewTop.setAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.in_bottom));
                mCardViewTop.setVisibility(View.VISIBLE);
                mCardViewBottom.setVisibility(View.VISIBLE);
                mTvAddressPrefix.setText(info.getName());
                mTvAddressSuffix.setText(info.getAddress());
                mUiSettings.setAllGesturesEnabled(false);
            }
        });
        final LinearLayoutManager manager = new LinearLayoutManager(getContext());
        mLvSearchAddress.setLayoutManager(manager);
        mLvSearchAddress.setAdapter(mSearchAddressAdapter);
    }

    private void initPoiSearchListView() {
        mSearchAddressAdapter = new SearchAddressAdapter(poiInfoListForSearch, currentLatLng);
        mSearchAddressAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {

            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                final PoiInfo poiInfo = (PoiInfo) adapter.gereplacedem(position);
                replacedert poiInfo != null;
                if (marker != null) {
                    marker.setPosition(poiInfo.getLocation());
                }
                final MapStatusUpdate status = MapStatusUpdateFactory.newLatLng(poiInfo.getLocation());
                mBaiduMap.setMapStatus(status);
                mTvAddressPrefix.setText(poiInfo.getName());
                mTvAddressSuffix.setText(poiInfo.getAddress());
                mUiSettings.setAllGesturesEnabled(false);
                mMapView.setVisibility(View.VISIBLE);
                mCardViewSearchAddress.setVisibility(View.GONE);
                mLvPoiSearchAddress.setVisibility(View.GONE);
                mLlInputText.setVisibility(View.GONE);
                mCardViewBottom.setAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.in_bottom));
                mCardViewTop.setAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.in_bottom));
                mCardViewBottom.setVisibility(View.VISIBLE);
                mCardViewTop.setVisibility(View.VISIBLE);
            }
        });
        final LinearLayoutManager manager = new LinearLayoutManager(getContext());
        mLvPoiSearchAddress.setLayoutManager(manager);
        mLvPoiSearchAddress.setAdapter(mSearchAddressAdapter);
    }

    /**
     * 展示搜索的布局
     */
    private void showSeachView() {
        mMapView.setVisibility(View.GONE);
        mCardViewSearchAddress.setVisibility(View.GONE);
        mLlPoiSearchAddress.setVisibility(View.VISIBLE);
    }

    /**
     * 展示地图的布局
     */
    private void showMapView() {
        mMapView.setVisibility(View.VISIBLE);
        mCardViewSearchAddress.setVisibility(View.VISIBLE);
        mLlPoiSearchAddress.setVisibility(View.GONE);
    }

    /**
     * 获取POI详情搜索结果,得到searchPoiDetail返回的搜索结果
     * V5.2.0版本之后,该方法废弃,使用{@link #onGetPoiDetailResult(PoiDetailSearchResult)}代替
     *
     * @param poiDetailResult POI详情检索结果
     */
    @Override
    public void onGetPoiDetailResult(PoiDetailResult poiDetailResult) {
        if (poiDetailResult.error != SearchResult.ERRORNO.NO_ERROR) {
            Toast.makeText(getContext(), "抱歉,未找到结果", Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(getContext(), poiDetailResult.getName() + ": " + poiDetailResult.getAddress(), Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onGetPoiDetailResult(PoiDetailSearchResult poiDetailSearchResult) {
        if (poiDetailSearchResult.error != SearchResult.ERRORNO.NO_ERROR) {
            Toast.makeText(getContext(), "抱歉,未找到结果", Toast.LENGTH_SHORT).show();
        } else {
            List<PoiDetailInfo> poiDetailInfoList = poiDetailSearchResult.getPoiDetailInfoList();
            if (null == poiDetailInfoList || poiDetailInfoList.isEmpty()) {
                Toast.makeText(getContext(), "抱歉,检索结果为空", Toast.LENGTH_SHORT).show();
                return;
            }
            for (int i = 0; i < poiDetailInfoList.size(); i++) {
                PoiDetailInfo poiDetailInfo = poiDetailInfoList.get(i);
                if (null != poiDetailInfo) {
                    Toast.makeText(getContext(), poiDetailInfo.getName() + ": " + poiDetailInfo.getAddress(), Toast.LENGTH_SHORT).show();
                }
            }
        }
    }

    @Override
    public void onGetPoiIndoorResult(PoiIndoorResult poiIndoorResult) {
    }

    public clreplaced MyLocationListener extends BDAbstractLocationListener {

        @Override
        public void onReceiveLocation(BDLocation location) {
            if (location == null || mMapView == null) {
                return;
            }
            Log.e(TAG, "当前“我”的位置:" + location.getAddrStr());
            if (location.getLocType() == BDLocation.TypeGpsLocation || location.getLocType() == BDLocation.TypeNetWorkLocation) {
                navigateTo(location);
                cityName = location.getCity();
                mTvCurrrentCity.setText(cityName);
                Log.e(TAG, "当前定位城市:" + location.getCity() + "定位地址: " + location.getAddress());
            }
        }
    }

    /**
     * 根据获取到的位置在地图上移动"我"的位置
     *
     * @param location
     */
    private void navigateTo(BDLocation location) {
        double longitude = location.getLongitude();
        double lareplacedude = location.getLareplacedude();
        String address = location.getAddrStr();
        if (isFirstLocation) {
            currentLatLng = new LatLng(lareplacedude, longitude);
            MapStatus.Builder builder = new MapStatus.Builder();
            MapStatus mapStatus = builder.target(currentLatLng).zoom(17.0f).build();
            mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(mapStatus));
            isFirstLocation = false;
            // 反向地理解析(含有poi列表)
            mGeoCoder.reverseGeoCode(new ReverseGeoCodeOption().location(currentLatLng).radius(radius));
        }
        MyLocationData.Builder locationBuilder = new MyLocationData.Builder();
        locationBuilder.lareplacedude(location.getLareplacedude());
        locationBuilder.longitude(location.getLongitude());
        MyLocationData locationData = locationBuilder.build();
        mBaiduMap.setMyLocationData(locationData);
    }

    /**
     * 根据收货地址的位置在地图上移动"我"的位置
     */
    private void navigateTo(double longitude, double lareplacedude) {
        if (isFirstLocation) {
            currentLatLng = new LatLng(lareplacedude, longitude);
            MapStatus.Builder builder = new MapStatus.Builder();
            MapStatus mapStatus = builder.target(currentLatLng).zoom(17.0f).build();
            mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(mapStatus));
            isFirstLocation = false;
            // 反向地理解析(含有poi列表)
            mGeoCoder.reverseGeoCode(new ReverseGeoCodeOption().location(currentLatLng));
        }
        MyLocationData.Builder locationBuilder = new MyLocationData.Builder();
        locationBuilder.lareplacedude(lareplacedude);
        locationBuilder.longitude(longitude);
        MyLocationData locationData = locationBuilder.build();
        mBaiduMap.setMyLocationData(locationData);
    }

    private void monitorEditTextChage() {
        mEtSearchKeyword.addTextChangedListener(new Texreplacedcher() {

            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                keyword = editable.toString();
                if (keyword.length() <= 0) {
                    // 当清空文本后展示地图,隐藏搜索结果
                    showMapView();
                    return;
                }
                /* 使用建议搜索服务获取建议列表,结果在onSuggestionResult()中更新 */
                /* 由于我们需要滑动地图展示周边poi,所以就不用建议搜索列表来搜索poi了,搜索时直接利用城市和输入的关键字进行城市内检索poi */
                // mSuggestionSearch.requestSuggestion((new SuggestionSearchOption())
                // .keyword(keyword)
                // .city(cityName));
                searchCityPoiAddress();
            }
        });
    }

    public void searchCityPoiAddress() {
        mPoiSearch.searchInCity((new PoiCitySearchOption()).city(cityName).keyword(// 必填
        keyword).pageCapacity(pageSize).pageNum(// 分页页码
        loadIndex));
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (mMapView != null) {
            mMapView.onDestroy();
        }
        // 当不需要定位图层时关闭定位图层
        mBaiduMap.setMyLocationEnabled(false);
        // 取消监听函数
        if (mLocationClient != null) {
            mLocationClient.unRegisterLocationListener(myListener);
        }
        mPoiSearch.destroy();
        mSuggestionSearch.destroy();
        mGeoCoder.destroy();
    }
}

See More Examples