com.baidu.location.BDLocationListener Java Examples

The following examples show how to use com.baidu.location.BDLocationListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GeolocationPlugin.java    From cordova-plugin-baidu-geolocation with MIT License 6 votes vote down vote up
private boolean watchPosition(JSONObject options, int watchId, final CallbackContext callback) {
  Log.i(TAG, "监听位置变化");
  Context ctx = cordova.getActivity().getApplicationContext();
  PositionOptions positionOpts = new PositionOptions(options);
  BDGeolocation geolocation = new BDGeolocation(ctx);
  store.put(watchId, geolocation);
  return geolocation.watchPosition(positionOpts, new BDLocationListener() {
    @Override
    public void onReceiveLocation(BDLocation location) {
      JSONArray message = new MessageBuilder(location).build();
      PluginResult result = new PluginResult(PluginResult.Status.OK, message);
      result.setKeepCallback(true);
      callback.sendPluginResult(result);
    }
  });
}
 
Example #2
Source File: MainActivity.java    From easyweather with MIT License 6 votes vote down vote up
@Override
    public void initData() {
        ButterKnife.bind(this);
        FragmentManager fm = getSupportFragmentManager();
        HomeFragment homeFragment = (HomeFragment) fm.findFragmentById(R.id.fragment_container);
        if (homeFragment == null) {
            homeFragment = HomeFragment.newInstance();
            fm.beginTransaction().add(R.id.fragment_container,homeFragment).commit();
        }

        mHomePresenter = new HomePresenter(homeFragment);
        BDLocationListener myListener = new MyLocationListener();
        MyApplication.getmLocationClient().registerLocationListener(myListener);

//
    }
 
Example #3
Source File: LocationLastKnownOnSubscribe.java    From FakeWeather with Apache License 2.0 6 votes vote down vote up
@Override
public void call(final Subscriber<? super BDLocation> subscriber) {
    BDLocation lateKnownLocation = LocationClient.get(context).getLastKnownLocation();
    if (lateKnownLocation != null) {
        subscriber.onNext(lateKnownLocation);
        subscriber.onCompleted();
    } else {
        BDLocationListener bdLocationListener = new BDLocationListener() {
            @Override
            public void onReceiveLocation(BDLocation bdLocation) {
                subscriber.onNext(bdLocation);
                subscriber.onCompleted();
            }
        };
        LocationClient.get(context).locate(bdLocationListener);
    }
}
 
Example #4
Source File: InviteBll.java    From PlayTogether with Apache License 2.0 5 votes vote down vote up
/**
 * 获得发邀请人的地址
 *
 * @param context
 * @return
 */
public Observable<AVGeoPoint> getLocation(final Context context)
{
	return Observable.create(new Observable.OnSubscribe<AVGeoPoint>()
	{
		@Override
		public void call(final Subscriber<? super AVGeoPoint> subscriber)
		{
			LocationClient client = LocationUtils.getLocationClient(context);
			client.registerLocationListener(new BDLocationListener()
			{
				@Override
				public void onReceiveLocation(BDLocation location)
				{
					if (location.getLocType() == BDLocation.TypeGpsLocation || location
									.getLocType() == BDLocation.TypeNetWorkLocation || location
									.getLocType() == BDLocation.TypeOffLineLocation)
					{
						subscriber.onNext(new AVGeoPoint(location.getLatitude(), location
										.getLongitude()));
					} else
					{
						subscriber.onNext(null);
					}
					LocationUtils.stopClient();
				}
			});
			client.start();
		}
	});
}
 
Example #5
Source File: GeolocationPlugin.java    From cordova-plugin-baidu-geolocation with MIT License 5 votes vote down vote up
private boolean getCurrentPosition(JSONObject options, final CallbackContext callback) {
  Log.i(TAG, "请求当前地理位置");
  Context ctx = cordova.getActivity().getApplicationContext();
  PositionOptions positionOpts = new PositionOptions(options);
  BDGeolocation geolocation = new BDGeolocation(ctx);
  return geolocation.getCurrentPosition(positionOpts, new BDLocationListener() {
    @Override
    public void onReceiveLocation(BDLocation location) {
      JSONArray message = new MessageBuilder(location).build();
      callback.success(message);
    }
  });
}
 
Example #6
Source File: BDGeolocation.java    From cordova-plugin-baidu-geolocation with MIT License 5 votes vote down vote up
public boolean watchPosition(PositionOptions options, BDLocationListener callback) {
  listener = callback;
  setOptions(options);
  client.registerLocationListener(listener);
  client.start();
  return true;
}
 
Example #7
Source File: BDGeolocation.java    From cordova-plugin-baidu-geolocation with MIT License 5 votes vote down vote up
public boolean getCurrentPosition(PositionOptions options, final BDLocationListener callback) {
  listener = new BDLocationListener() {
    @Override
    public void onReceiveLocation(BDLocation location) {
      callback.onReceiveLocation(location);
      clearWatch();
    }
  };
  setOptions(options);
  client.registerLocationListener(listener);
  client.start();
  return true;
}
 
Example #8
Source File: GpsUtil.java    From MyWeather with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化
 */
public GpsUtil(Context ctx, BDLocationListener locationListener) {
    context = ctx;
    try {
        mLocationClient = new LocationClient(context.getApplicationContext());
        mLocationClient.registerLocationListener(locationListener);    //注册监听函数
        initLocation();
        mLocationClient.start();
    } catch (Exception e) {
        Log.e("GpsUtil error : ", e.getMessage(), e);
    }
}
 
Example #9
Source File: LocationService.java    From ESeal with Apache License 2.0 5 votes vote down vote up
/***
 * @param listener
 * @return
 */

public boolean registerListener(BDLocationListener listener) {
    boolean isSuccess = false;
    if (listener != null) {
        client.registerLocationListener(listener);
        isSuccess = true;
    }
    return isSuccess;
}
 
Example #10
Source File: LocationService.java    From ESeal with Apache License 2.0 5 votes vote down vote up
/***
 * @param listener
 * @return
 */

public boolean registerListener(BDLocationListener listener) {
    boolean isSuccess = false;
    if (listener != null) {
        client.registerLocationListener(listener);
        isSuccess = true;
    }
    return isSuccess;
}
 
Example #11
Source File: BaiduLocation.java    From DongWeather with Apache License 2.0 5 votes vote down vote up
/***
 *
 * @param listener
 * @return
 */

public boolean registerListener(BDLocationListener listener){
    boolean isSuccess = false;
    if(listener != null){
        client.registerLocationListener(listener);
        isSuccess = true;
    }
    return  isSuccess;
}
 
Example #12
Source File: LocationOnSubscribe.java    From FakeWeather with Apache License 2.0 5 votes vote down vote up
@Override
public void call(final Subscriber<? super BDLocation> subscriber) {
    BDLocationListener bdLocationListener = new BDLocationListener() {
        @Override
        public void onReceiveLocation(BDLocation bdLocation) {
            subscriber.onNext(bdLocation);
            subscriber.onCompleted();
        }
    };
    LocationClient.get(context).locate(bdLocationListener);
}
 
Example #13
Source File: LocationClient.java    From FakeWeather with Apache License 2.0 5 votes vote down vote up
public void locate(final BDLocationListener bdLocationListener) {
    final BDLocationListener realListener = new BDLocationListener() {
        @Override
        public void onReceiveLocation(BDLocation bdLocation) {
            bdLocationListener.onReceiveLocation(bdLocation);
            //防止内存溢出
            realClient.unRegisterLocationListener(this);
            stop();
        }
    };
    realClient.registerLocationListener(realListener);
    if (!realClient.isStarted()) {
        realClient.start();
    }
}
 
Example #14
Source File: LocationService.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
/***
 * 
 * @param listener
 * @return
 */

public boolean registerListener(BDLocationListener listener){
	boolean isSuccess = false;
	if(listener != null){
		client.registerLocationListener(listener);
		isSuccess = true;
	}
	return  isSuccess;
}
 
Example #15
Source File: BaiduRxLocationManager.java    From RxLocation with Apache License 2.0 5 votes vote down vote up
@Override
public void call(final Subscriber<? super BDLocation> subscriber) {
    mListener = new BDLocationListener() {
        @Override
        public void onReceiveLocation(final BDLocation bdLocation) {
            subscriber.onNext(bdLocation);
        }

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

        }
    };
    mLocationClient.registerLocationListener(mListener);
    synchronized (RxLocationListener.class) {
        mLocationClient.start();
    }
    subscriber.add(new Subscription() {
        @Override
        public void unsubscribe() {
            if (!subscriber.isUnsubscribed()) {
                subscriber.unsubscribe();
            }
            removeListener();
        }

        @Override
        public boolean isUnsubscribed() {
            return subscriber.isUnsubscribed();
        }
    });
}
 
Example #16
Source File: GpsUtil.java    From FoodOrdering with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化
 */
public GpsUtil(Context ctx, BDLocationListener locationListener) {
    context = ctx;
    try {
        mLocationClient = new LocationClient(context.getApplicationContext());
        mLocationClient.registerLocationListener(locationListener);    //注册监听函数
        initLocation();
        mLocationClient.start();
    } catch (Exception e) {
        Log.e("GpsUtil error : ", e.getMessage(), e);
    }
}
 
Example #17
Source File: LocationManager.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
public void locate(BDLocationListener mListener){
    bdLocationListener = mListener;
    mLocationClient.registerLocationListener(bdLocationListener);
    LocationClientOption option = new LocationClientOption();
    option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
    option.setIsNeedAddress(true);
    mLocationClient.setLocOption(option);
    mLocationClient.requestLocation();
    mLocationClient.start();
}
 
Example #18
Source File: LocationUtils.java    From SmartOrnament with Apache License 2.0 4 votes vote down vote up
private void initLocation() {
        LocationClientOption option = new LocationClientOption();
        option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy
        );//可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
        option.setCoorType("bd09ll");//可选,默认gcj02,设置返回的定位结果坐标系
        int span=100;
        option.setScanSpan(span);//大于等于1000ms时,使用定时定位模式。调用requestLocation()后,每隔设定的时间定定一次位
        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);

        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.getLatitude());
                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.getAltitude());// 单位:米
//                     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();


            }
        });
    }
 
Example #19
Source File: LocationService.java    From ESeal with Apache License 2.0 4 votes vote down vote up
public void unregisterListener(BDLocationListener listener) {
    if (listener != null) {
        client.unRegisterLocationListener(listener);
    }
}
 
Example #20
Source File: LocationService.java    From ESeal with Apache License 2.0 4 votes vote down vote up
public void unregisterListener(BDLocationListener listener) {
    if (listener != null) {
        client.unRegisterLocationListener(listener);
    }
}
 
Example #21
Source File: LocationService.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
public void unregisterListener(BDLocationListener listener){
	if(listener != null){
		client.unRegisterLocationListener(listener);
	}
}
 
Example #22
Source File: BaiduLocation.java    From DongWeather with Apache License 2.0 4 votes vote down vote up
public void unregisterListener(BDLocationListener listener){
    if(listener != null){
        client.unRegisterLocationListener(listener);
    }
}