@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---------------------------");
  }
 protected void initMapController(MapView mapView) {
   mMapController = mapView.getController();
   mMapController.enableClick(true);
   mMapController.setZoom(ZOOM_LEVEL);
   mapView.setBuiltInZoomControls(true);
   mapView.showScaleControl(true);
 }
Exemple #3
0
  public void initView() {

    iv_list = (ImageView) findViewById(R.id.iv_list);
    iv_list.setOnClickListener(this);
    iv_loc = (ImageView) findViewById(R.id.iv_loc);
    iv_loc.setOnClickListener(this);
    tv_title_right = (TextView) findViewById(R.id.tv_title_button);
    tv_title_right.setText("3km" + " >");
    tv_title_right.setVisibility(View.VISIBLE);
    tv_title_right.setOnClickListener(this);

    // 油价,距离信息
    ll_summary = (LinearLayout) findViewById(R.id.ll_summary);
    ll_summary.setOnClickListener(this);
    tv_name = (TextView) findViewById(R.id.tv_name);
    tv_distance = (TextView) findViewById(R.id.tv_distance);
    tv_price_a = (TextView) findViewById(R.id.tv_price_a);
    tv_price_b = (TextView) findViewById(R.id.tv_price_b);

    // MapView
    mMapView = (MapView) findViewById(R.id.bmapView);
    mMapView.showScaleControl(false);
    mMapView.showZoomControls(false);
    mBaiduMap = mMapView.getMap();
    // MapView配置定位到当前位置
    mBaiduMap.setMyLocationConfigeration(
        new MyLocationConfiguration(MyLocationConfiguration.LocationMode.FOLLOWING, true, null));
    mBaiduMap.setMyLocationEnabled(true);
    // 注册监听
    mLocationClient = new LocationClient(mContext);
    mLocationClient.registerLocationListener(mListener);

    LocationClientOption option = new LocationClientOption();
    option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy); // 高精度;
    // Battery_Saving:低精度.
    option.setCoorType("bd09ll"); // 返回国测局经纬度坐标系:gcj02 返回百度墨卡托坐标系 :bd09
    // 返回百度经纬度坐标系 :bd09ll
    option.setScanSpan(0); // 设置扫描间隔,单位毫秒,当<1000(1s)时,定时定位无效
    option.setIsNeedAddress(true); // 设置是否需要地址信息,默认为无地址
    option.setNeedDeviceDirect(true); // 在网络定位时,是否需要设备方向
    mLocationClient.setLocOption(option);
  }
  private void initViews() {
    orderInfo = getIntent().getParcelableExtra(AutoCon.ORDER_INFO);

    mainTech = (TextView) findViewById(R.id.main_tech);
    mMapView = (MapView) findViewById(R.id.bdmapView);
    distance = (TextView) findViewById(R.id.distance);
    indentImage = (ImageView) findViewById(R.id.indent_image);
    indentText = (TextView) findViewById(R.id.indent_text);
    workTime = (TextView) findViewById(R.id.work_time);
    orderType = (TextView) findViewById(R.id.order_type);
    orderOwner = (TextView) findViewById(R.id.create_order_people);
    shopsLocation = (TextView) findViewById(R.id.shops_location);
    shopsAlias = (TextView) findViewById(R.id.shops_name);
    workNotes = (TextView) findViewById(R.id.work_notes);

    baiduMap = mMapView.getMap(); // 管理具体的某一个MapView对象,缩放,旋转,平移
    MapStatusUpdate mapStatusUpdate =
        MapStatusUpdateFactory.zoomTo(BaiduMapUtil.defaultLevel); // 默认级别12
    baiduMap.setMapStatus(mapStatusUpdate); // 设置缩放级别

    BaiduMapUtil.hiddenBaiduLogo(mMapView); // 隐藏百度广告图标
    mMapView.showZoomControls(false);
    mMapView.showScaleControl(true); // 默认是true,显示标尺

    BaiduMapUtil.initData();
    setListener();

    if (orderInfo != null) {
      orderId = orderInfo.getId();
      mainTech.setText(orderInfo.getMainTech().getName());
      setData(orderInfo);
    } else {
      T.show(this, R.string.loading_data_failure);
      return;
    }
  }
Exemple #5
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // 初始化地图管理器
    mMapManager = new BMapManager(getApplication());
    mMapManager.init(accessKey, new MyMKGeneralListener());
    // 初始化各种与地图无关的成员变量
    appInit();

    regeisterSensorManager();

    textShow = (TextView) findViewById(R.id.textShow);
    textShow.setTextSize(TextShowTextSize);
    // 初始化mapview对象,并且设置显示缩放控件
    mMapView = (MapView) findViewById(R.id.bmapsView);

    mMapView.setBuiltInZoomControls(true);
    mMapView.showScaleControl(true);
    mMapView.setDoubleClickZooming(false);
    // 定义地图控件,获取mapview的控制,并把地图范围定位在宿舍
    mMapView.regMapViewListener(mMapManager, new MyMKMapViewListener());
    mMapView.regMapTouchListner(new MyMKMapTouchListener());
    mMapController = mMapView.getController();
    // 初始化locationClient服务
    clientInit();
    // 此处启动,将会在第一次定位后自动关闭
    mLocationClient.start();
    // 使用上一次退出时的位置数据作为初始化的地点
    mMapController.animateTo(new GeoPoint(appData.lastLatitude, appData.lastLongitude));
    mMapController.setZoom(appData.lastZoom);

    // 此处进行定时器设置,定时器每隔500ms执行一次
    handler =
        new Handler() {
          public void handleMessage(Message msg) {
            if (msg.what != MainActivity.UPDATE_TEXT) {
              return;
            }
            // 截图
            if (isCut) {
              cutSpeed++;
              if (cutSpeed % 8 == 1) {
                mMapView.getCurrentMap();
              }
            }

            if (!mLocationClient.isStarted() || appData.isFirst) {
              appData.textShowStrings[0] = "未启动导航功能";
              appData.textShowStrings[1] = "";
              textShow.setTextColor(Color.BLACK);
              appData.updateTextShow();
              mMapController.setRotation(0);
              return;
            }

            GeoPoint curPos = new GeoPoint(appData.lastLatitude, appData.lastLongitude);
            double radius = roadData.getRadius(curPos);
            double curSpeed, safeSpeed;

            // 返回的应该是米每秒
            safeSpeed = appData.getSafeSpeed(radius);
            if (safeSpeed > 120.0 / 3.6) {
              safeSpeed = 120.0 / 3.6;
            }

            // 该速度为 千米每小时
            curSpeed = appData.lastSpeed / 3.6f;

            appData.textShowStrings[0] = "当前车速为:" + (int) (curSpeed * 3.6) + "km/h";
            if (curSpeed <= safeSpeed) {
              appData.textShowStrings[1] = "安全车速为:" + (int) (safeSpeed * 3.6) + "km/h";
              textShow.setTextColor(Color.BLUE);
            } else {
              appData.textShowStrings[1] =
                  "安全车速为:" + (int) (safeSpeed * 3.6) + "km/h" + "\n您已超速!请迅速减速";
              textShow.setTextColor(Color.RED);
              Toast.makeText(MainActivity.this, "您已超过安全车速,请迅速减速!", Toast.LENGTH_LONG).show();
            }
            appData.updateTextShow();
          }
        };

    // 启动定时器
    new Timer()
        .schedule(
            new TimerTask() {
              @Override
              public void run() {
                // TODO Auto-generated method stub
                Message msg = new Message();
                msg.what = MainActivity.UPDATE_TEXT;
                handler.sendMessage(msg);
              }
            },
            500,
            500);
  }
Exemple #6
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    type = getIntent().getIntExtra("type", 1);

    title = getIntent().getStringExtra("title");

    setContentView(R.layout.activity_map);

    mapView = (MapView) findViewById(R.id.mapview);
    ll_search = (LinearLayout) findViewById(R.id.ll_search);
    ibtn_back = (ImageButton) findViewById(R.id.ibtn_back);
    tv_title = (TextView) findViewById(R.id.tv_title);
    rl_info = (RelativeLayout) findViewById(R.id.rl_info);
    btn_do = (Button) findViewById(R.id.btn_do);
    tv_name = (TextView) findViewById(R.id.tv_name);
    tv_distance = (TextView) findViewById(R.id.tv_distance);
    tv_addr = (TextView) findViewById(R.id.tv_addr);

    ibtn_back.setOnClickListener(this);
    btn_do.setOnClickListener(this);

    if (!TextUtils.isEmpty(title)) {
      tv_title.setText(title);
    }

    baiduMap = mapView.getMap();
    // 显示定位图层
    baiduMap.setMyLocationEnabled(true);

    baiduMap.setOnMapLoadedCallback(
        new BaiduMap.OnMapLoadedCallback() {
          @Override
          public void onMapLoaded() {
            if (drivingRouteOverlay != null) {
              drivingRouteOverlay.zoomToSpan();
            }

            if (overlayManager != null) {
              overlayManager.zoomToSpan();
            }
          }
        });

    baiduMap.setOnMapClickListener(
        new BaiduMap.OnMapClickListener() {
          @Override
          public void onMapClick(LatLng latLng) {
            if (type == 1) {
              rl_info.setVisibility(View.GONE);
            }
          }

          @Override
          public boolean onMapPoiClick(MapPoi mapPoi) {
            return false;
          }
        });

    mapView.showScaleControl(true);

    BDLocUtil.registerLocListener(this);
    BDLocUtil.requestLocation();

    myOrientationListener = new MyOrientationListener(this);
    myOrientationListener.setOnOritentationListener(this);
    myOrientationListener.start();

    if (type == 1) {
      // add marker
      data = (List<MyPoiInfo>) getIntent().getSerializableExtra("data");
      addMarker2Map();
    } else {
      // route plan
      toInfo = (MyPoiInfo) getIntent().getSerializableExtra("to");

      requestRoutePlan(toInfo);
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {

    requestWindowFeature(Window.FEATURE_NO_TITLE); // 去掉标题栏
    super.onCreate(savedInstanceState);

    SDKInitializer.initialize(getApplicationContext());
    setContentView(R.layout.navigate);
    // 地图初始化
    mMapView = (MapView) findViewById(R.id.mapview_navi);
    mBaiduMap = mMapView.getMap();
    mMapView.showZoomControls(false);
    mMapView.showScaleControl(true);
    // 开启定位图层
    mBaiduMap.setMyLocationEnabled(true);
    // 开启罗盘
    mBaiduMap.getUiSettings().setCompassEnabled(true);
    // 定位初始化
    mLocClient = new LocationClient(this);
    mLocClient.registerLocationListener(myListener);
    LocationClientOption option = new LocationClientOption();
    option.setOpenGps(true); // 打开gps
    option.setCoorType("bd09ll"); // 设置坐标类型为百度经纬度坐标
    option.setScanSpan(1000);
    mLocClient.setLocOption(option);
    mLocClient.start();

    mBaiduMap.setOnMapLongClickListener(MyLongClickListener);

    // 初始化导航引擎
    //       BaiduNaviManager.getInstance().initEngine(this, getSdcardDir(),
    //       		mNaviEngineInitListener,ACCESS_KEY,mKeyVerifyListener);
    /*
            BaiduNaviManager.getInstance().initEngine(this, getSdcardDir(),
            mNaviEngineInitListener, new LBSAuthManagerListener() {
                @Override
                public void onAuthResult(int status, String msg) {
                    String str = null;
                    if (0 == status) {
                        str = "key校验成功!";
                    } else {
                        str = "key校验失败, " + msg;
                    }
                    Toast.makeText(NavigateActivity.this, str,
                            Toast.LENGTH_LONG).show();
                }
            });
    */
    boolean isInitSuccess =
        BaiduNaviManager.getInstance().checkEngineStatus(getApplicationContext());
    Toast.makeText(NavigateActivity.this, "isInitSuccess" + isInitSuccess, Toast.LENGTH_LONG)
        .show();

    // 设置策略
    TextView SetStrategy = (TextView) findViewById(R.id.tvStrategy);
    SetStrategy.setOnClickListener(
        new OnClickListener() {

          @SuppressWarnings("deprecation")
          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            showDialog(0);
          }
        });

    // 规划路径
    TextView CalcRoute = (TextView) findViewById(R.id.tvCalcRoutes);
    CalcRoute.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            if (hasEndpoint = true) {
              drivintResultIndex = 0;
              nextLineBtn.setEnabled(false);
              drivingSearch(drivintResultIndex); // 驾车路线规划
              // startCalcRoute(NL_Net_Mode.NL_Net_Mode_OnLine);
            } else {
              Toast.makeText(NavigateActivity.this, "请先设置终点!", Toast.LENGTH_SHORT).show();
            }
          }
        });
    routePlanSearch = RoutePlanSearch.newInstance();
    routePlanSearch.setOnGetRoutePlanResultListener(routePlanResultListener);

    // 开始导航
    TextView StartNavigate = (TextView) findViewById(R.id.tvStartNavi);
    StartNavigate.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            //		launchNavigator();
            startNaviByClient(); // 调用客户端的方式发起导航
          }
        });

    // 下一条路径
    nextLineBtn = (Button) findViewById(R.id.nextline_btn);
    nextLineBtn.setEnabled(false);
    nextLineBtn.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            drivingSearch(++drivintResultIndex);
          }
        });
  }