/** 插件主入口 */ @Override public boolean execute(String action, final JSONArray args, CallbackContext callbackContext) throws JSONException { LOG.d(LOG_TAG, "BaiduPush#execute"); boolean ret = false; if ("getCurrentPosition".equalsIgnoreCase(action)) { cbCtx = callbackContext; PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT); pluginResult.setKeepCallback(true); cbCtx.sendPluginResult(pluginResult); if (mLocationClient == null) { mLocationClient = new LocationClient(this.webView.getContext()); mLocationClient.registerLocationListener(myListener); // 配置定位SDK参数 initLocation(); } mLocationClient.start(); ret = true; } return ret; }
public void getUserLocation() { BDLocationListener listener = new MyLocationListener(); locationClient = new LocationClient(MyApplication.getContext()); initLocation(); locationClient.registerLocationListener(listener); locationClient.start(); }
@Override public void init() { // 设置是否显示比例尺控件 mapView.showScaleControl(true); // 设置是否显示缩放控件 mapView.showZoomControls(false); baiduMap = mapView.getMap(); // 设置监听 baiduMap.setOnMapClickListener( new OnMapClickListener() { @Override public boolean onMapPoiClick(MapPoi mapPoi) { return false; } @Override public void onMapClick(final LatLng latLng) { System.out.println(latLng.latitude + "--" + latLng.longitude); geoCoder.reverseGeoCode(new ReverseGeoCodeOption().location(latLng)); showWaiting(true); ok.setEnabled(false); markFirstLocation(); markClickLocation(latLng); } }); // 检索 geoCoder = GeoCoder.newInstance(); geoCoder.setOnGetGeoCodeResultListener(getGeoCoderResultListener); // 开始定位 client = new LocationClient(getApplicationContext()); client.setLocOption(getDefaultLocationClientOption()); client.registerLocationListener(dbListener); client.start(); // waiting的layout的初始化 waitingAnimation = AnimationUtils.loadAnimation(SelectLocationActivity.this, R.anim.anim_waiting); waitingIcon.setAnimation(waitingAnimation); showWaiting(true); // 位置列表初始化 adapter = new LocationAdapter(); locationListView.setAdapter(adapter); locationListView.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { locationList.get(currentLocation).setSelected(false); locationList.get(position).setSelected(true); currentLocation = position; adapter.notifyDataSetChanged(); // 重置标志 markFirstLocation(); markClickLocation(locationList.get(position).getLatLng()); } }); // 按钮 back.setOnClickListener(clickListener); ok.setOnClickListener(clickListener); ok.setEnabled(false); Log.e("tag", "---------------------create---------------------------"); }
private void initLocation() { // TODO Auto-generated method stub mLocClient = new LocationClient(this); mLocClient.registerLocationListener(new MyLocationListenner()); setLocationOption(); mLocClient.start(); }
/** 开始定位 */ public void startLocation() { if (mLocationClient != null && !mLocationClient.isStarted()) { mLocationClient.registerLocationListener(mLocationListener); mLocationClient.start(); mLocationClient.requestLocation(); } }
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.i(BaiduMapAll.LOG_TAG, "启动LocationApplication!"); MyLog.i(BaiduMapAll.LOG_TAG, "启动LocationApplication!"); // this.setUploadUrl(intent.getStringExtra("uploadUrl")); // this.setGps_interval(intent.getIntExtra("gps_interval",0)); // String params_str=intent.getStringExtra("params"); // try { // if(params_str!=null){ // this.setParams(new JSONObject(params_str)); // // } // // } catch (JSONException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // Log.e(BaiduMapAll.LOG_TAG, e.getMessage()); // } // mLocationClient.getLocOption().setScanSpan(this.getGps_interval()); initLocation(); mLocationClient.start(); mLocationClient.requestLocation(); // toast("开始获取gps信息了", Toast.LENGTH_LONG); // LOG.i(BaiduMapAll.LOG_TAG, "开始获取gps信息了================================================"); return super.onStartCommand(intent, flags, startId); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mLocationClient = new LocationClient(getActivity().getApplicationContext()); LocationClientOption option = new LocationClientOption(); option.setOpenGps(true); option.setCoorType("bd09ll"); option.setIsNeedAddress(true); // so that we can get city at init. option.setScanSpan(1000); option.setProdName("meishi"); option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy); mLocationClient.setLocOption(option); mLocationClient.registerLocationListener( new BDLocationListener() { @Override public void onReceiveLocation(BDLocation location) { if (location == null) { return; } String city = location.getCity(); if (city != null) { Log.d(TAG, city); ((MeishiApplication) getActivity().getApplication()).setCurrentCity(city); mLocationClient.stop(); currentCity.setText("当前城市: " + location.getCountry() + city); currentCity.setGravity(Gravity.CENTER); searchButton.setEnabled(true); } } }); mLocationClient.start(); }
/** init mapview */ public void initMap() { mMapView = (MapView) findViewById(R.id.bmapView); mBaiduMap = mMapView.getMap(); // remove map logo mMapView.removeViewAt(1); int childCount = mMapView.getChildCount(); View zoom = null; for (int i = 0; i < childCount; i++) { View child = mMapView.getChildAt(i); if (child instanceof ZoomControls) { zoom = child; break; } } zoom.setVisibility(View.GONE); mBaiduMap = mMapView.getMap(); UiSettings mUiSettings = mBaiduMap.getUiSettings(); mUiSettings.setCompassEnabled(false); mBaiduMap.setMyLocationEnabled(true); mLocClient = new LocationClient(this); mLocClient.registerLocationListener(myListener); LocationClientOption option = new LocationClientOption(); option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy); option.setOpenGps(true); option.setCoorType("bd09ll"); option.setScanSpan(1000); option.setIsNeedAddress(true); mLocClient.setLocOption(option); mLocClient.start(); }
/* init methods */ private void initialized() { // 初始化db if (null == dbHelper) dbHelper = new DBHelper(this, D.DB_VERSION); try { rdb = dbHelper.getWritableDatabase(); wdb = dbHelper.getReadableDatabase(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } String path2 = getApplicationContext().getFilesDir().getPath(); path2 = path2.substring(0, path2.lastIndexOf("/")) + "/databases/"; putProviceTo(); putimagrfromassats(); File file = new File(path2, D.DB_NAME_PROVINCE); pcdDB = SQLiteDatabase.openOrCreateDatabase(file, null); // 初始化百度定位 mLocationClient = getmLocationClient(); BDLocationListener locationListener = new BDLocationListener() { @Override public void onReceiveLocation(BDLocation location) { ZhongTuanApp.getInstance().setLocation(location); mLocationClient.stop(); } }; mLocationClient.registerLocationListener(locationListener); mLocationClient.start(); }
public void start() { synchronized (objLock) { if (client != null && !client.isStarted()) { client.start(); } } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.child_layout); init(); setSupportActionBar(toolbar); JMessageClient.registerEventReceiver(this); JMessageClient.setNotificationMode(JMessageClient.NOTI_MODE_NO_NOTIFICATION); listener = new LocationListener(); toolbar.setSubtitle("孩子"); toolbar.setNavigationIcon(R.mipmap.ic_keyboard_backspace_white_24dp); toolbar.setNavigationOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); location.setText("软件已开启,请按home键退出"); client = new LocationClient(this); client.registerLocationListener(listener); LocationClientOption option = new LocationClientOption(); option.setOpenGps(true); // 打开gps option.setCoorType("bd09ll"); // 设置坐标类型 client.setLocOption(option); client.start(); }
/** * 请求baidu获取当前地址 * * @param listener */ public static void requestLocation(final LocationRequestListener listener) { LocationClientOption option = new LocationClientOption(); option.setLocationMode(LocationClientOption.LocationMode.Battery_Saving); option.setIsNeedAddress(true); option.setIsNeedLocationPoiList(true); final LocationClient locationClient = new LocationClient(JYApplication.getContext(), option); locationClient.registerLocationListener( new BDLocationListener() { @Override public void onReceiveLocation(BDLocation bdLocation) { String city = bdLocation.getCity(); String province = bdLocation.getProvince(); if (city == null || province == null) { listener.onRequestLocationFailed("定位失败, 请手动选择地区!"); } else { if (province.contains("省")) { province = province.replace("省", ""); } if (city.contains("市")) { city = city.replace("市", ""); } listener.onRequestLocationSuccess(province, city); } locationClient.stop(); } }); locationClient.start(); }
@Override public void onProviderEnabled(String provider) { Log.d(TAG, "onProviderEnabled"); if (!mLocationClient.isStarted()) { mLocationClient.start(); } }
/** * 定位当前位置 * * @return */ public BDLocation getLocation() { mLocationClient = new LocationClient(mContext.getApplicationContext()); // mLocationClient.registerLocationListener(myListener); // mLocationClient.setAK("eWeT5sSsDuzlGzfaVGyShoeG"); // LocationClientOption option = new LocationClientOption(); // option.setOpenGps(false); // option.setAddrType("all"); // option.setServiceName("com.baidu.location.service_v2.9"); mLocationClient.registerLocationListener(myListener); // mLocationClient.setAK("eWeT5sSsDuzlGzfaVGyShoeG"); LocationClientOption option = new LocationClientOption(); option.setOpenGps(false); option.setAddrType("all"); option.setServiceName("com.baidu.location.service_v2.9"); // 返回国测局经纬度坐标系 coor=gcj02 // 返回百度墨卡托坐标系 coor=bd09 // 返回百度经纬度坐标系 coor=bd09ll option.setCoorType("gcj02"); option.setScanSpan(900); option.disableCache(true); option.setPriority(LocationClientOption.NetWorkFirst); mLocationClient.setLocOption(option); if (mLocationClient != null) { mLocationClient.start(); mLocationClient.requestLocation(); } else { } return null; }
public void starBaiduLBS() { if (mLocationClient != null && !baiduIsStart) { // Log.d("DDDS", "SSSSSTART start():"); mLocationClient.start(); baiduIsStart = true; } }
@Override public void onStart() { super.onStart(); if (!mLocationClient.isStarted()) { mLocationClient.start(); } }
public static void getLocation(final Context context, final LocationCallback callback) { // Log.e("xxx_loc", "2"); LocationClient locationClient = new LocationClient(context); MyLocationListener mMyLocationListener = new MyLocationListener(callback); locationClient.registerLocationListener(mMyLocationListener); // 设置定位参数 LocationClientOption option = new LocationClientOption(); option.setOpenGps(true); option.setProdName("com.xgf.wineserver"); option.setLocationMode(LocationMode.Hight_Accuracy); // 设置定位模式 option.setCoorType("gcj02"); // 返回的定位结果是百度经纬度,默认值gcj02 int span = 1000; option.setScanSpan(span); // 设置发起定位请求的间隔时间为1000ms option.setIsNeedAddress(true); locationClient.setLocOption(option); // Log.e("xxx_loc", "3"); locationClient.start(); // locationClient.requestLocation(); GeofenceClient mGeofenceClient = new GeofenceClient(context); }
@Override public boolean onOptionsItemSelected(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.menu_navi: // 启动导航跟踪功能,默认是关闭的 if (!mLocationClient.isStarted()) { mLocationClient.start(); menuItem.setTitle("关闭导航"); } else { mLocationClient.stop(); menuItem.setTitle("启动导航"); } break; case R.id.menu_vehicle: // 启动菜单设置用的activity entryMenuVehicle(); break; case R.id.menu_cut: if (isCut == false) { isCut = true; menuItem.setTitle("关闭截图"); } else { isCut = false; menuItem.setTitle("启动截图"); } break; default: } return true; }
@Override protected void onStart() { super.onStart(); mBaiduMap.setMyLocationEnabled(true); mLocationClient.start(); myOrientationListener.start(); }
@Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); mMapView.onResume(); mLocationClient.start(); }
@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); initLocation(); mLocationClient.start(); // 开始定位 }
private void initLocClient() { // 开启定位图层 mBaiduMap.setMyLocationEnabled(true); mBaiduMap.setMyLocationConfigeration( new MyLocationConfigeration( com.baidu.mapapi.map.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); } }
public LocationClient getLocationClient() { if (mLocationClient == null) { mLocationClient = getmLocationClient(); mLocationClient.start(); } return mLocationClient; }
private void initBaiduLocClient() { mLocationClient = new LocationClient(this.getApplicationContext()); mMyLocationListener = new MyLocationListener(); mLocationClient.registerLocationListener(mMyLocationListener); initLocation(); mLocationClient.start(); }
private void dependToShowDialog() { if (!SomeUtil.hasSystemFeatureGPS(this)) { // 系统没有 GPS 模块就不弹出开启 GPS 的对话框 return; } if (!SomeUtil.isGPSOn(this)) { mDialog = new Dialog(this, R.style.Dialog_style_dim2); View view = View.inflate(this, R.layout.dialog_my_vehicle_condition, null); TextView txt1 = (TextView) view.findViewById(R.id.txt_dialog_my_vehicle_condition_heading); TextView txt2 = (TextView) view.findViewById(R.id.txt_dialog_my_vehicle_condition_subheading); ImageView ivYes = (ImageView) view.findViewById(R.id.iv_dialog_my_vehicle_condition_yes); ImageView ivNo = (ImageView) view.findViewById(R.id.iv_dialog_my_vehicle_condition_no); txt1.setText(getResources().getString(R.string.myVehicleCondition_heading_no_gps)); txt2.setText(getResources().getString(R.string.myVehicleCondition_subheading_no_gps)); ivYes.setOnClickListener(mDialogOnClickListener); ivNo.setOnClickListener(mDialogOnClickListener); mDialog.setContentView(view); mDialog.setCanceledOnTouchOutside(true); mDialog.getWindow().setType((WindowManager.LayoutParams.TYPE_SYSTEM_ALERT)); mDialog.show(); } else { mLocationClient.start(); } }
@Override public void onCreate() { // TODO Auto-generated method stub // Toast.makeText(getApplicationContext(), "service 被创建", Toast.LENGTH_SHORT).show(); app = (FindYouApplication) this.getApplication(); if (app.mBMapManager == null) { app.mBMapManager = new BMapManager(getApplicationContext()); app.mBMapManager.init(FindYouApplication.strKey, null); } // 定位初始化 mLocClient = new LocationClient(getApplicationContext()); locData = new LocationData(); mainLocationListenner mainListener = new mainLocationListenner(); mLocClient.registerLocationListener(mainListener); LocationClientOption option = new LocationClientOption(); option.setOpenGps(true); // 打开gps option.setCoorType("bd09ll"); // 设置坐标类型 option.setScanSpan(5000); // 设置定位时间 mLocClient.setLocOption(option); mLocClient.start(); // 初始化搜索模块 注册搜索事件监听 mSearch = new MKSearch(); mSearch.init(app.mBMapManager, new MySearchListenner()); super.onCreate(); }
@Override protected void onResume() { mMapView.onResume(); if (mLocClient != null) { mLocClient.start(); } super.onResume(); }
@Override protected void onStart() { // TODO Auto-generated method stub super.onStart(); mapdu.setMyLocationEnabled(true); if (!client.isStarted()) client.start(); // 开启方向传感器 myorientaion.start(); }
protected void initLoc() { LocationClientOption option = new LocationClientOption(); option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy); option.setCoorType("bd09"); option.setIsNeedAddress(true); option.setScanSpan(50000); mLocationClient.setLocOption(option); mLocationClient.start(); }
/** * 开始定位 * * @param option 定位参数 */ public void beginOrientation(LocationClientOption option) { mLocClient = new LocationClient(context); mLocClient.registerLocationListener(myListener); if (option == null) { option = setLocationOption(); } mLocClient.setLocOption(option); mLocClient.start(); }