Java Code Examples for com.baidu.location.LocationClient#start()
The following examples show how to use
com.baidu.location.LocationClient#start() .
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: BaiduMapRouteFragment.java From BmapLite with GNU General Public License v3.0 | 6 votes |
public void initLocationSDK() { // 定位初始化 mLocClient = new LocationClient(getActivity()); mLocClient.registerLocationListener(this); LocationClientOption option = new LocationClientOption(); option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy); option.setCoorType("gcj02"); option.setOpenGps(true); option.setScanSpan(1000); option.setIsNeedAltitude(true); option.setIsNeedAddress(false); mLocClient.setLocOption(option); MyLocationConfiguration configuration = new MyLocationConfiguration(MyLocationConfiguration.LocationMode.NORMAL, true, null); mBaiduMap.setMyLocationConfiguration(configuration); mLocClient.start(); isFirstLoc = false; }
Example 2
Source File: BaiduMapSelectPoiFragment.java From BmapLite with GNU General Public License v3.0 | 6 votes |
public void initBaiduSdk() { // 定位初始化 mLocClient = new LocationClient(getActivity()); mLocClient.registerLocationListener(this); LocationClientOption option = new LocationClientOption(); option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy); option.setCoorType("gcj02"); option.setOpenGps(true); option.setScanSpan(1000); option.setIsNeedAltitude(true); option.setIsNeedAddress(false); mLocClient.setLocOption(option); MyLocationConfiguration configuration = new MyLocationConfiguration(MyLocationConfiguration.LocationMode.NORMAL, true, null); mBaiduMap.setMyLocationConfiguration(configuration); mLocClient.start(); }
Example 3
Source File: RouteBaiduBusActivity.java From BmapLite with GNU General Public License v3.0 | 6 votes |
public void initLocationSDK() { // 定位初始化 mLocClient = new LocationClient(this); mLocClient.registerLocationListener(this); LocationClientOption option = new LocationClientOption(); option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy); option.setCoorType("gcj02"); option.setOpenGps(true); option.setScanSpan(1000); option.setIsNeedAltitude(true); option.setIsNeedAddress(false); mLocClient.setLocOption(option); MyLocationConfiguration configuration = new MyLocationConfiguration(MyLocationConfiguration.LocationMode.NORMAL, true, null); mBaiduMap.setMyLocationConfiguration(configuration); mLocClient.start(); isFirstLoc = false; }
Example 4
Source File: IndexDelegate.java From FastWaiMai with MIT License | 6 votes |
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(); }
Example 5
Source File: MainActivity.java From Study_Android_Demo with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //初始化地图控件 mapView = (MapView) findViewById(R.id.mapview); mBaiduMap = mapView.getMap(); //初始化定位 mLocationClient = new LocationClient(getApplicationContext()); //初始化定位 initLocation(); //注册监听函数 mLocationClient.registerLocationListener(this); //开始定位,定位完成后,不管是否成功,都会调用上面的监听函数中的方法 mLocationClient.start(); //设置地图的点击事件 setMapListenter(); }
Example 6
Source File: BaiduMapRouteFragment.java From BmapLite with Apache License 2.0 | 6 votes |
public void initLocationSDK() { // 定位初始化 mLocClient = new LocationClient(getActivity()); mLocClient.registerLocationListener(this); LocationClientOption option = new LocationClientOption(); option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy); option.setCoorType("gcj02"); option.setOpenGps(true); option.setScanSpan(1000); option.setIsNeedAltitude(true); option.setIsNeedAddress(false); mLocClient.setLocOption(option); MyLocationConfiguration configuration = new MyLocationConfiguration(MyLocationConfiguration.LocationMode.NORMAL, true, null); mBaiduMap.setMyLocationConfiguration(configuration); mLocClient.start(); isFirstLoc = false; }
Example 7
Source File: BaiduMapSelectPoiFragment.java From BmapLite with Apache License 2.0 | 6 votes |
public void initBaiduSdk() { // 定位初始化 mLocClient = new LocationClient(getActivity()); mLocClient.registerLocationListener(this); LocationClientOption option = new LocationClientOption(); option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy); option.setCoorType("gcj02"); option.setOpenGps(true); option.setScanSpan(1000); option.setIsNeedAltitude(true); option.setIsNeedAddress(false); mLocClient.setLocOption(option); MyLocationConfiguration configuration = new MyLocationConfiguration(MyLocationConfiguration.LocationMode.NORMAL, true, null); mBaiduMap.setMyLocationConfiguration(configuration); mLocClient.start(); }
Example 8
Source File: WBNearbyActivity.java From Simpler with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_wb_nearby); ButterKnife.bind(this); //声明LocationClient类 mLocationClient = new LocationClient(getApplicationContext()); //注册监听函数 mLocationClient.registerLocationListener(myListener); mLocationClient.setLocOption(BDLocationUtil.getLocationClientOption()); mLocationClient.start(); // 每次刷新微博数 mRefreshCount = BaseSettings.sSettings.refreshCount; mAdapter = new StatusListAdapter(this, null); mSwipeRefresh.setRecyclerViewAndAdapter(mRvStatuses, mAdapter); mSwipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { // 刷新 if (TextUtils.isEmpty(mLongitude) || TextUtils.isEmpty(mLatitude)) { mSwipeRefresh.setRefreshing(false); return; } mPage = 1; loadStatuses(1, true); mSwipeRefresh.setRefreshing(true); } }); mSwipeRefresh.setOnLoadingListener(new DSwipeRefresh.OnLoadingListener() { @Override public void onLoading() { if (mPage != 0) { mAdapter.setFooterInfo(getString(R.string.data_loading)); loadStatuses(mPage, false); } } }); }
Example 9
Source File: WelcomeActivity.java From Social with Apache License 2.0 | 5 votes |
private void locate(){ //发布代码 mLocationClient = new LocationClient(getApplicationContext()); //声明LocationClient类 mLocationClient.registerLocationListener(myListener); //注册监听函数 initLocation(); //调用前判断网络连接状态 try{ mLocationClient.start(); }catch (Exception e){ e.printStackTrace(); } }
Example 10
Source File: BDLocationService.java From Social with Apache License 2.0 | 5 votes |
@Override public int onStartCommand(Intent intent, int flags, int startId) { //发布代码 mLocationClient = new LocationClient(getApplicationContext()); //声明LocationClient类 mLocationClient.registerLocationListener(myListener); //注册监听函数 initLocation(); //调用前判断网络连接状态 try{ mLocationClient.start(); }catch (Exception e){ e.printStackTrace(); } return super.onStartCommand(intent, flags, startId); }
Example 11
Source File: WeatherService.java From Dainty with Apache License 2.0 | 5 votes |
@Override public int onStartCommand(Intent intent, int flags, int startId) { mLocationClient = new LocationClient(getApplicationContext()); MyLocationListener myListener = new MyLocationListener(); initLocation(); mLocationClient.registerLocationListener(myListener); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); city = sharedPreferences.getString("cityName", ""); mLocationClient.start(); return super.onStartCommand(intent, flags, startId); }
Example 12
Source File: GpsUtil.java From FoodOrdering with Apache License 2.0 | 5 votes |
/** * 初始化 */ 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 13
Source File: BaiduLocationService.java From GeometricWeather with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void requestLocation(Context context, @NonNull LocationCallback callback){ this.callback = callback; LocationClientOption option = new LocationClientOption(); option.setLocationMode(LocationClientOption.LocationMode.Battery_Saving); // 可选,默认高精度,设置定位模式,高精度,低功耗,仅设备 option.setCoorType("wgs84"); // 可选,默认gcj02,设置返回的定位结果坐标系 option.setScanSpan(0); // 可选,默认0,即仅定位一次,设置发起定位请求的间隔需要大于等于1000ms才是有效的 option.setIsNeedAddress(true); // 可选,设置是否需要地址信息,默认不需要 option.setOpenGps(false); // 可选,默认false,设置是否使用gps option.setLocationNotify(false); // 可选,默认false,设置是否当gps有效时按照1S1次频率输出GPS结果 option.setIsNeedLocationDescribe(false); // 可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近” option.setIsNeedLocationPoiList(false); // 可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到 option.setIgnoreKillProcess(false); // 可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死 option.SetIgnoreCacheException(true); // 可选,默认false,设置是否收集CRASH信息,默认收集 option.setEnableSimulateGps(false); // 可选,默认false,设置是否需要过滤gps仿真结果,默认需要 option.setWifiCacheTimeOut(5 * 60 * 1000); // 可选,如果设置了该接口,首次启动定位时,会先判断当前WiFi是否超出有效期,若超出有效期,会先重新扫描WiFi,然后定位 client = new LocationClient(context.getApplicationContext()); client.setLocOption(option); client.registerLocationListener(listener); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { manager.createNotificationChannel(getLocationNotificationChannel(context)); client.enableLocInForeground( GeometricWeather.NOTIFICATION_ID_LOCATION, getLocationNotification(context)); } client.start(); }
Example 14
Source File: GpsUtil.java From MyWeather with Apache License 2.0 | 5 votes |
/** * 初始化 */ 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 15
Source File: LocationActivity.java From Conquer with Apache License 2.0 | 5 votes |
private void initLocClient() { // 开启定位图层 mBaiduMap.setMyLocationEnabled(true); mBaiduMap.setMyLocationConfigeration(new MyLocationConfigeration(MyLocationConfigeration.LocationMode.NORMAL, true, null)); // 定位初始化 mLocClient = new LocationClient(this); mLocClient.registerLocationListener(myListener); LocationClientOption option = new LocationClientOption(); option.setProdName("bmobim");// 设置产品线 option.setOpenGps(true);// 打开gps option.setCoorType("bd09ll"); // 设置坐标类型 option.setScanSpan(1000); option.setOpenGps(true); option.setIsNeedAddress(true); option.setIgnoreKillProcess(true); mLocClient.setLocOption(option); mLocClient.start(); if (mLocClient != null && mLocClient.isStarted()) mLocClient.requestLocation(); if (lastLocation != null) { // 显示在地图上 LatLng ll = new LatLng(lastLocation.getLatitude(), lastLocation.getLongitude()); MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll); mBaiduMap.animateMapStatus(u); } }
Example 16
Source File: BaiduMapFragment.java From BmapLite with Apache License 2.0 | 5 votes |
public void initLocationSdk() { // 定位初始化 mLocClient = new LocationClient(getActivity()); mLocClient.registerLocationListener(this); LocationClientOption option = new LocationClientOption(); option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy); option.setCoorType("gcj02"); option.setOpenGps(true); option.setScanSpan(1000); option.setIsNeedAltitude(true); option.setIsNeedAddress(false); mLocClient.setLocOption(option); MyLocationConfiguration configuration = new MyLocationConfiguration(MyLocationConfiguration.LocationMode.NORMAL, true, null); mBaiduMap.setMyLocationConfiguration(configuration); mLocClient.start(); try { LocationManager locManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); if (!locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { onMessage(getResources().getString(R.string.gps_enabled_false)); } } catch (Exception e) { e.printStackTrace(); } }
Example 17
Source File: RouteService.java From Mobike with Apache License 2.0 | 4 votes |
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(); }
Example 18
Source File: LocationDelegate.java From FastWaiMai with MIT License | 4 votes |
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(); }
Example 19
Source File: AddressEditDelegate.java From FastWaiMai with MIT License | 4 votes |
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(); }
Example 20
Source File: MainActivity.java From MoveMapLocation with Apache License 2.0 | 4 votes |
private void initView() { mMapView = (MapView) findViewById(R.id.main_bdmap); mBaiduMap = mMapView.getMap(); poisLL = (ListView) findViewById(R.id.main_pois); topRL = (RelativeLayout) findViewById(R.id.main_top_RL); searchAddress = (EditText) findViewById(R.id.main_search_address); searchPois = (ListView) findViewById(R.id.main_search_pois); //定义地图状态 MapStatus mMapStatus = new MapStatus.Builder().zoom(18).build(); MapStatusUpdate mMapStatusUpdate = MapStatusUpdateFactory.newMapStatus(mMapStatus); //改变地图状态 mBaiduMap.setMapStatus(mMapStatusUpdate); //地图状态改变相关监听 mBaiduMap.setOnMapStatusChangeListener(this); //开启定位图层 mBaiduMap.setMyLocationEnabled(true); //定位图层显示方式 mCurrentMode = MyLocationConfiguration.LocationMode.NORMAL; /** * 设置定位图层配置信息,只有先允许定位图层后设置定位图层配置信息才会生效 * customMarker用户自定义定位图标 * enableDirection是否允许显示方向信息 * locationMode定位图层显示方式 */ mBaiduMap.setMyLocationConfigeration(new MyLocationConfiguration(mCurrentMode, true, null)); //初始化定位 mLocClient = new LocationClient(this); //注册定位监听 mLocClient.registerLocationListener(this); //定位选项 LocationClientOption option = new LocationClientOption(); /** * coorType - 取值有3个: * 返回国测局经纬度坐标系:gcj02 * 返回百度墨卡托坐标系 :bd09 * 返回百度经纬度坐标系 :bd09ll */ option.setCoorType("bd09ll"); //设置是否需要地址信息,默认为无地址 option.setIsNeedAddress(true); //设置是否需要返回位置语义化信息,可以在BDLocation.getLocationDescribe()中得到数据,ex:"在天安门附近", 可以用作地址信息的补充 option.setIsNeedLocationDescribe(true); //设置是否需要返回位置POI信息,可以在BDLocation.getPoiList()中得到数据 option.setIsNeedLocationPoiList(true); /** * 设置定位模式 * Battery_Saving * 低功耗模式 * Device_Sensors * 仅设备(Gps)模式 * Hight_Accuracy * 高精度模式 */ option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy); //设置是否打开gps进行定位 option.setOpenGps(true); //设置扫描间隔,单位是毫秒 当<1000(1s)时,定时定位无效 option.setScanSpan(1000); //设置 LocationClientOption mLocClient.setLocOption(option); //开始定位 mLocClient.start(); }