예제 #1
0
  // 请求线路规划
  private void requestRoutePlan(final MyPoiInfo to) {

    if (to == null) return;

    if (rpSearch == null) {
      rpSearch = RoutePlanSearch.newInstance();
    }

    rpSearch.setOnGetRoutePlanResultListener(
        new OnGetRoutePlanResultListener() {
          @Override
          public void onGetWalkingRouteResult(WalkingRouteResult walkingRouteResult) {}

          @Override
          public void onGetTransitRouteResult(TransitRouteResult transitRouteResult) {}

          @Override
          public void onGetDrivingRouteResult(DrivingRouteResult drivingRouteResult) {
            if (drivingRouteResult == null
                || drivingRouteResult.error != SearchResult.ERRORNO.NO_ERROR) {
              ToastHelper.toastShort(MapActivity.this, "查询失败,请重试!");
              return;
            }

            if (drivingRouteResult.error == SearchResult.ERRORNO.NO_ERROR) {

              type = 2;

              baiduMap.clear();
              drivingRouteOverlay = new DrivingRouteOverlay(baiduMap);
              baiduMap.setOnMarkerClickListener(drivingRouteOverlay);
              baiduMap.removeMarkerClickListener(overlayManager);
              drivingRouteOverlay.setData(drivingRouteResult.getRouteLines().get(0));
              drivingRouteOverlay.addToMap();
              drivingRouteOverlay.zoomToSpan();

              showInfoView(to);
            }
          }
        });

    if (cLoc == null) {
      cLoc = BDLocUtil.getLastLocation();
    }

    PlanNode fromNode = PlanNode.withLocation(new LatLng(cLoc.getLatitude(), cLoc.getLongitude()));
    PlanNode toNode = PlanNode.withLocation(new LatLng(to.lat, to.lng));

    rpSearch.drivingSearch(new DrivingRoutePlanOption().from(fromNode).to(toNode));
  }
예제 #2
0
  @Override
  protected void onDestroy() {

    BDLocUtil.unregisterLocListener(this);
    myOrientationListener.stop();

    if (mapView != null) {
      mapView.onDestroy();
      mapView = null;
    }

    if (rpSearch != null) {
      rpSearch.destroy();
      rpSearch = null;
    }
    super.onDestroy();
  }
예제 #3
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);
    }
  }