Example #1
0
  /* 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();
  }
Example #2
0
 private void initData() {
   mLocationClient = new LocationClient(getActivity());
   mLocationListener = new MyLocationListener();
   mLocationClient.registerLocationListener(mLocationListener);
   LocationClientOption option = new LocationClientOption();
   option.setCoorType("bd09ll");
   option.setIsNeedAddress(true);
   option.setOpenGps(true);
   mLocationClient.setLocOption(option);
   timeHandler =
       new Handler() {
         @Override
         public void handleMessage(Message msg) {
           super.handleMessage(msg);
           switch (msg.what) {
             case 1:
               long systemTime = System.currentTimeMillis();
               CharSequence sysTime = DateFormat.format("hh:mm", systemTime);
               try {
                 time.setText(sysTime);
               } catch (Exception e) {
                 e.printStackTrace();
               }
           }
         }
       };
 }
Example #3
0
 @Override
 public void onStop() {
   super.onStop();
   if (mLocationClient.isStarted()) {
     mLocationClient.stop();
   }
 }
Example #4
0
 public void getUserLocation() {
   BDLocationListener listener = new MyLocationListener();
   locationClient = new LocationClient(MyApplication.getContext());
   initLocation();
   locationClient.registerLocationListener(listener);
   locationClient.start();
 }
 public void start() {
   synchronized (objLock) {
     if (client != null && !client.isStarted()) {
       client.start();
     }
   }
 }
Example #6
0
  /** 初始化。 */
  public void init() {
    synchronized (this) {
      if (first) {
        first = false;
        readCfg();
      }

      stop();

      locationClient = new LocationClient(App.context);
      locationClient.registerLocationListener(this);

      LocationClientOption option = new LocationClientOption();
      // 设置定位模式:高精度(这种定位模式下,会同时使用网络定位和GPS定位,优先返回最高精度的定位结果)
      option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
      // 默认值gcj02,返回国测局经纬度坐标系
      option.setCoorType("bd09ll");
      // 设置发起定位请求的间隔时间
      option.setScanSpan(10 * 1000);
      // 返回的定位结果包含地址信息
      option.setIsNeedAddress(true);

      locationClient.setLocOption(option);
    }
  }
  private void initLocation() {

    mLocationMode = com.baidu.mapapi.map.MyLocationConfiguration.LocationMode.NORMAL;
    mLocationClient = new LocationClient(this);
    mLocationListener = new MyLocationListener();
    mLocationClient.registerLocationListener(mLocationListener);

    LocationClientOption option = new LocationClientOption();
    option.setCoorType("bd09ll");
    option.setIsNeedAddress(true);
    option.setOpenGps(true);
    option.setScanSpan(1000);

    mLocationClient.setLocOption(option);
    // 初始化图标
    mIconLocation = BitmapDescriptorFactory.fromResource(R.drawable.navi_map_gps_locked);

    myOrientationListener = new MyOrientationListener(context);

    myOrientationListener.setOnOrientationListener(
        new OnOrientationListener() {

          @Override
          public void onOrientationChanged(float x) {
            mCurrentX = x;
          }
        });
  }
Example #8
0
 private void stopListener() {
   // TODO Auto-generated method stub
   if (mLocationClient != null && mLocationClient.isStarted()) {
     mLocationClient.stop(); // �رն�λSDK
     mLocationClient = null;
   }
 }
  @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---------------------------");
  }
  @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 onDestroy() {
   if (mLocationClient != null && mLocationClient.isStarted()) {
     mLocationClient.stop();
   }
   super.onDestroy();
 }
Example #12
0
 /** 开始定位 */
 public void startLocation() {
   if (mLocationClient != null && !mLocationClient.isStarted()) {
     mLocationClient.registerLocationListener(mLocationListener);
     mLocationClient.start();
     mLocationClient.requestLocation();
   }
 }
  @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();
  }
Example #14
0
  /** 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();
  }
 @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();
 }
Example #16
0
 private void initLocation() {
   // TODO Auto-generated method stub
   mLocClient = new LocationClient(this);
   mLocClient.registerLocationListener(new MyLocationListenner());
   setLocationOption();
   mLocClient.start();
 }
Example #17
0
  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);
    }
  }
  /** 插件主入口 */
  @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;
  }
Example #19
0
 @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;
 }
 private void initBaiduLocClient() {
   mLocationClient = new LocationClient(this.getApplicationContext());
   mMyLocationListener = new MyLocationListener();
   mLocationClient.registerLocationListener(mMyLocationListener);
   initLocation();
   mLocationClient.start();
 }
Example #21
0
  /**
   * 请求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();
  }
Example #22
0
  /**
   * 定位当前位置
   *
   * @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;
  }
Example #23
0
  @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();
  }
Example #24
0
  private void initLocation() {
    // TODO Auto-generated method stub
    client = new LocationClient(this);
    locationlistener = new Mylocation();
    client.registerLocationListener(locationlistener);
    // 设置location的一些参数
    LocationClientOption option = new LocationClientOption();
    option.setCoorType("bd09ll");
    option.setIsNeedAddress(true); // 获得当前的地址
    option.setOpenGps(true);
    option.setScanSpan(1000);
    client.setLocOption(option); // 设置完成上述功能
    // 初始化图标
    mylocationbitmap = BitmapDescriptorFactory.fromResource(R.drawable.arrow);
    // 初始化 方向传感器
    myorientaion = new MyOrientation(this);
    myorientaion.setChanged(
        new OrientainChanged() {

          @Override
          public void Onchanged(float x) {
            // TODO Auto-generated method stub
            CurrentX = x;
          }
        });
  }
Example #25
0
 @Override
 public void onProviderEnabled(String provider) {
   Log.d(TAG, "onProviderEnabled");
   if (!mLocationClient.isStarted()) {
     mLocationClient.start();
   }
 }
Example #26
0
  private void showMapWithLocationClient() {
    progressDialog = new ProgressDialog(this);
    progressDialog.setCanceledOnTouchOutside(false);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog.setMessage("正在确定你的位置...");

    progressDialog.setOnCancelListener(
        new OnCancelListener() {

          public void onCancel(DialogInterface arg0) {
            if (progressDialog.isShowing()) {
              progressDialog.dismiss();
            }
            Log.d("map", "cancel retrieve location");
            finish();
          }
        });

    progressDialog.show();

    mLocClient = new LocationClient(this);
    mLocClient.registerLocationListener(myListener);

    LocationClientOption option = new LocationClientOption();
    option.setOpenGps(true); // 打开gps
    // option.setCoorType("bd09ll"); //设置坐标类型
    // Johnson change to use gcj02 coordination. chinese national standard
    // so need to conver to bd09 everytime when draw on baidu map
    option.setCoorType("gcj02");
    option.setScanSpan(30000);
    option.setAddrType("all");
    mLocClient.setLocOption(option);
  }
Example #27
0
  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);
  }
 private void initBaiduLocation() {
   LocationClientOption option = new LocationClientOption();
   option.setCoorType("bd09ll");
   locationClient = new LocationClient(context);
   locationClient.setLocOption(option);
   locationClient.registerLocationListener(new LocationListener());
 }
Example #29
0
  @Override
  protected void onDestroy() {
    super.onDestroy();
    if (mLocationClient != null && mLocationClient.isStarted()) {

      mLocationClient.stop();
    }
  }
Example #30
0
 /**
  * 开始定位
  *
  * @param option 定位参数
  */
 public void beginOrientation(LocationClientOption option) {
   mLocClient = new LocationClient(context);
   mLocClient.registerLocationListener(myListener);
   if (option == null) {
     option = setLocationOption();
   }
   mLocClient.setLocOption(option);
   mLocClient.start();
 }