package com.tofly.ghrq_route.module.gps.service;

import android.content.Context;

import com.esri.arcgisruntime.geometry.Point;

/*百度定位*/
public class BaiduLocationHelper{

    /*private LocationService locationServiceBaidu;

    private GeoCoder geocodeBaidu = null; // 搜索模块，也可去掉地图模块独立使用*/

    private Context mContext;

    protected Point mLocation = null;

    protected String mAddress = null;

    private boolean isFirstLoc = true;


    public BaiduLocationHelper(Context context){
        this.mContext = context;

        init();
    }

    private void init(){
        initBaiduLocationService();
        initBaiduGeocodeSearch();
    }

    /**
     * 定位监听
     */

    public void resetLocation(){
        isFirstLoc = true;
    }

    /*定位服务*/
    private void initBaiduLocationService() {
      /*
        locationServiceBaidu = new LocationService(this);
        locationServiceBaidu.registerListener(locationListenerBaidu);//定位的监听
        locationServiceBaidu.setLocationOption(locationServiceBaidu.getDefaultLocationClientOption());
        locationServiceBaidu.start();//开始定位
       */
    }

    public interface BaiduLocChangeListener{
        void onLocationed(Point location, String addr);
    }

    private BaiduLocChangeListener mLocationListener = null;

    public void setMapLocationListener(BaiduLocChangeListener locationListener) {
        this.mLocationListener = locationListener;
    }

    /*
    private BDLocationListener locationListenerBaidu = new BDLocationListener() {
        private final static int LOCATION_TYPE_GPS = 1;
        private final static int LOCATION_TYPE_CELL = 2;
        private final static int LOCATION_TYPE_WIFI = 3;

        @Override
        public void onReceiveLocation(BDLocation location) {
            if (null != location && location.getLocType() != BDLocation.TypeServerError) {
                if (isNeedBaiduLocation) {
                    Address baiduAddress = location.getAddress();
                    if (baiduAddress == null)
                        return;

                    Point location = new Point(location.getLongitude(), location.getLatitude())
                    String address = location.getAddress().city + " " + location.getAddress().district + "  " + location.getAddress().street;

                    if (mLocationListener != null)
                        mLocationListener.onLocationed(location, address);
                }
            }
        }

        @Override
        public void onConnectHotSpotMessage(String s, int i) {

        }
    };
    */

    /**
     * 地址编码
     */

    /*地址编码，翻地址编码服务*/
    private void initBaiduGeocodeSearch(){
        /*
          geocodeBaidu = GeoCoder.newInstance();
          geocodeBaidu.setOnGetGeoCodeResultListener(this);
        */
    }

    private void reserveLocationBaidu(double lon, double lan) {
        /*
          BigDecimal bg1 = new BigDecimal(lon);
          lon = bg1.setScale(6, BigDecimal.ROUND_HALF_UP).doubleValue();
          BigDecimal bg2 = new BigDecimal(lan);
          lan = bg2.setScale(6, BigDecimal.ROUND_HALF_UP).doubleValue();
          LatLng ptCenter = new LatLng(lan, lon);

          geocodeBaidu.reverseGeoCode(new ReverseGeoCodeOption().location(ptCenter));
        */
    }

    public interface BaiduReserveLocListener{
        void onLocationReserved(boolean isSuccess, String addr);
    }

    private BaiduReserveLocListener mReserveLocListener = null;

    public void setReserveLocListener(BaiduReserveLocListener mReserveLocListener) {
        this.mReserveLocListener = mReserveLocListener;
    }

/*    @Override
    public void onGetGeoCodeResult(GeoCodeResult result) {
        String address = result.getAddress();
        Log.w("TAG", "onGetGeoCodeResult: address = " + address);
    }

    @Override
    public void onGetReverseGeoCodeResult(ReverseGeoCodeResult result) {
        if (result == null || result.error != SearchResult.ERRORNO.NO_ERROR) {
            toast("抱歉，未能找到结果");
            return;

        }

        String address = result.getAddressDetail().city + "  " +
                result.getAddressDetail().district + "  " + result.getAddressDetail().street +
                result.getAddressDetail().streetNumber;
        mAddress = address;

        if (mReserveLocListener != null)
            mReserveLocListener.onLocationReserved(true, address);
    }*/


    public void onDestroy(){
        /*locationServiceBaidu.unregisterListener(locationListenerBaidu);
        locationServiceBaidu.stop();
        geocodeBaidu.destroy();*/
    }
}
