Exemplo n.º 1
0
 private void stopListener() {
   // TODO Auto-generated method stub
   if (mLocationClient != null && mLocationClient.isStarted()) {
     mLocationClient.stop(); // �رն�λSDK
     mLocationClient = null;
   }
 }
 @Override
 public void onDestroy() {
   if (mLocationClient != null && mLocationClient.isStarted()) {
     mLocationClient.stop();
   }
   super.onDestroy();
 }
Exemplo n.º 3
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);
    }
  }
Exemplo n.º 4
0
 @Override
 public void onProviderEnabled(String provider) {
   Log.d(TAG, "onProviderEnabled");
   if (!mLocationClient.isStarted()) {
     mLocationClient.start();
   }
 }
Exemplo n.º 5
0
 /** 开始定位 */
 public void startLocation() {
   if (mLocationClient != null && !mLocationClient.isStarted()) {
     mLocationClient.registerLocationListener(mLocationListener);
     mLocationClient.start();
     mLocationClient.requestLocation();
   }
 }
Exemplo n.º 6
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;
 }
Exemplo n.º 7
0
 @Override
 public void onStop() {
   super.onStop();
   if (mLocationClient.isStarted()) {
     mLocationClient.stop();
   }
 }
 public void start() {
   synchronized (objLock) {
     if (client != null && !client.isStarted()) {
       client.start();
     }
   }
 }
Exemplo n.º 9
0
  @Override
  protected void onDestroy() {
    super.onDestroy();
    if (mLocationClient != null && mLocationClient.isStarted()) {

      mLocationClient.stop();
    }
  }
Exemplo n.º 10
0
 @Override
 protected void onStart() {
   // TODO Auto-generated method stub
   super.onStart();
   mapdu.setMyLocationEnabled(true);
   if (!client.isStarted()) client.start();
   // 开启方向传感器
   myorientaion.start();
 }
 /**
  * *
  *
  * @param option
  * @return isSuccessSetOption
  */
 public boolean setLocationOption(LocationClientOption option) {
   boolean isSuccess = false;
   if (option != null) {
     if (client.isStarted()) client.stop();
     DIYoption = option;
     client.setLocOption(option);
   }
   return isSuccess;
 }
Exemplo n.º 12
0
  /** 启动百度地图。 */
  public synchronized void start() {
    synchronized (this) {
      if (first) {
        init();
      }

      if (locationClient != null && !locationClient.isStarted()) {
        stopTime();
        locationClient.start();
      }
    }
  }
Exemplo n.º 13
0
  private void initBaiduMap() {
    mapView = (MapView) findViewById(R.id.bmapView);
    baiduMap = mapView.getMap();
    baiduMap.setMaxAndMinZoomLevel(18, 13);
    IntentFilter iFilter = new IntentFilter();
    iFilter.addAction(SDKInitializer.SDK_BROADTCAST_ACTION_STRING_PERMISSION_CHECK_ERROR);
    iFilter.addAction(SDKInitializer.SDK_BROADCAST_ACTION_STRING_NETWORK_ERROR);
    receiver = new BaiduReceiver();
    registerReceiver(receiver, iFilter);

    geoCoder = GeoCoder.newInstance();
    geoCoder.setOnGetGeoCodeResultListener(this);

    Intent intent = getIntent();
    intentType = intent.getStringExtra(TYPE);
    initActionBar(R.string.chat_position);
    if (intentType.equals(TYPE_SELECT)) {
      // 选择发送位置
      // 开启定位图层
      baiduMap.setMyLocationEnabled(true);
      baiduMap.setMyLocationConfigeration(
          new MyLocationConfigeration(MyLocationConfigeration.LocationMode.NORMAL, true, null));
      // 定位初始化
      locClient = new LocationClient(this);
      locClient.registerLocationListener(myListener);
      LocationClientOption option = new LocationClientOption();
      option.setProdName("avosim");
      option.setOpenGps(true);
      option.setCoorType("bd09ll");
      option.setScanSpan(1000);
      option.setOpenGps(true);
      option.setIsNeedAddress(true);
      option.setIgnoreKillProcess(true);
      locClient.setLocOption(option);
      locClient.start();
      if (locClient != null && locClient.isStarted()) {
        locClient.requestLocation();
      }
      if (lastLocation != null) {
        // 显示在地图上
        LatLng ll = new LatLng(lastLocation.getLatitude(), lastLocation.getLongitude());
        MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);
        baiduMap.animateMapStatus(u);
      }
    } else {
      Bundle b = intent.getExtras();
      LatLng latlng = new LatLng(b.getDouble(LATITUDE), b.getDouble(LONGITUDE)); // 维度在前,经度在后
      baiduMap.setMapStatus(MapStatusUpdateFactory.newLatLng(latlng));
      OverlayOptions ooA = new MarkerOptions().position(latlng).icon(descriptor).zIndex(9);
      baiduMap.addOverlay(ooA);
    }
  }
Exemplo n.º 14
0
 @Override
 protected void onDestroy() {
   // TODO Auto-generated method stub
   mMapView.destroy();
   if (mMapManager != null) {
     mMapManager.destroy();
     mMapManager = null;
   }
   if (mLocationClient.isStarted()) {
     mLocationClient.stop();
   }
   super.onDestroy();
 }
Exemplo n.º 15
0
  private void initLocation() {
    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);
    if (!mLocationClient.isStarted()) {

      mLocationClient.start();
    }
  }
Exemplo n.º 16
0
 @Override
 protected void onDestroy() {
   if (mLocClient != null && mLocClient.isStarted()) {
     // 退出时销毁定位
     mLocClient.stop();
   }
   // 关闭定位图层
   mBaiduMap.setMyLocationEnabled(false);
   mMapView.onDestroy();
   mMapView = null;
   // 取消监听 SDK 广播
   unregisterReceiver(mReceiver);
   super.onDestroy();
   // 回收 bitmap 资源
   bdgeo.recycle();
 }
Exemplo n.º 17
0
 @Override
 protected void onDestroy() {
   if (locClient != null && locClient.isStarted()) {
     // 退出时销毁定位
     locClient.stop();
   }
   // 关闭定位图层
   baiduMap.setMyLocationEnabled(false);
   mapView.onDestroy();
   mapView = null;
   // 取消监听 SDK 广播
   unregisterReceiver(receiver);
   super.onDestroy();
   // 回收 bitmap 资源
   descriptor.recycle();
 }
Exemplo n.º 18
0
 @Override
 public void onClick(View v) {
   switch (v.getId()) {
     case R.id.selectlocation_back:
       SelectLocationActivity.this.setResult(RESULT_CANCELED);
       SelectLocationActivity.this.finish();
       break;
     case R.id.selectlocation_ok:
       LocationPoint locationPoint = locationList.get(currentLocation);
       Intent intent = new Intent();
       intent.putExtra("location_address", locationPoint.detail);
       intent.putExtra("location_latitude", locationPoint.getLatLng().latitude);
       intent.putExtra("location_longitude", locationPoint.getLatLng().longitude);
       SelectLocationActivity.this.setResult(RESULT_OK, intent);
       if (client != null && !client.isStarted()) {
         client.stop();
       }
       SelectLocationActivity.this.finish();
       break;
     default:
       break;
   }
 }
Exemplo n.º 19
0
 @Override
 public void onGetReverseGeoCodeResult(ReverseGeoCodeResult result) {
   showWaiting(false);
   if (result != null) {
     if (result.getPoiList() == null) {
       showToast("获取位置信息失败,请重新获取");
       SelectLocationActivity.this.setResult(RESULT_CANCELED);
       SelectLocationActivity.this.finish();
       return;
     }
     locationList.clear();
     LocationPoint firstPoint =
         new LocationPoint("[ 位置 ]", result.getAddress(), result.getLocation());
     firstPoint.setSelected(true);
     locationList.add(firstPoint);
     List<PoiInfo> allAddrList = result.getPoiList();
     for (PoiInfo info : allAddrList) {
       LocationPoint point = new LocationPoint(info.name, info.address, info.location);
       point.setSelected(false);
       locationList.add(point);
       System.out.println("地址:" + info.name + ":" + info.address);
     }
     currentLocation = 0;
     adapter.notifyDataSetChanged();
     ok.setEnabled(true);
   } else {
     System.out.println("---->null--------------------");
     if (client != null && !client.isStarted()) {
       ToastUtil.show(SelectLocationActivity.this, "定位不成功,正在自动重新定位");
       client.start();
     } else {
       showToast("获取位置信息失败,请重新获取");
       SelectLocationActivity.this.setResult(RESULT_CANCELED);
       SelectLocationActivity.this.finish();
     }
   }
 }
Exemplo n.º 20
0
 /** 关闭百度地图。 */
 public void stop() {
   if (locationClient != null && locationClient.isStarted()) {
     locationClient.stop();
   }
 }
Exemplo n.º 21
0
 /** 停止定位 */
 public void stopLocation() {
   if (mLocationClient != null && mLocationClient.isStarted()) {
     mLocationClient.unRegisterLocationListener(mLocationListener);
     mLocationClient.stop();
   }
 }
Exemplo n.º 22
0
 public void detect() {
   if (!locationClient.isStarted()) locationClient.start();
   locationClient.requestLocation();
 }