private void showMapViewRoutes(List<GPSInfo> lstWgs84HashMap) {
    ArrayList<GeoPoint> lstWgs84GeoPoint = RoutesHelper.getWgs84GeoPoint(lstWgs84HashMap);

    // mRoutesOverlay
    if (mMapView != null) {
      try {
        if (mRoutesOverlay != null) {
          if (mMapView.getOverlays().contains(mRoutesOverlay)) {
            mMapView.getOverlays().remove(mRoutesOverlay);
            mRoutesOverlay = null;
          }
        }
        mRoutesOverlay = new RoutesOverlay(mPathActivity, mMapView);
        {
          mRoutesOverlay.setOnOverlayEventListener(this);

          mRoutesOverlay.setData(lstWgs84GeoPoint);
        }
        mMapView.getOverlays().add(0, mRoutesOverlay);
        mMapView.invalidate();
        mMapView.getController().animateTo(lstWgs84GeoPoint.get(0));
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  @Override
  public void onClick(View v) {
    switch (v.getId()) {
      case R.id.btnAddress:
        mapView.getOverlays().clear(); // 清除公交站点的标识
        mapView.invalidate();
        GeoPoint geoPoint = new GeoPoint((int) (39.915 * 1e6), (int) (116.454 * 1e6));
        EditText tvAdr = (EditText) findViewById(R.id.etAddress);
        // 根据中心点geoPoint在1000半径内查询KFC
        mkSearch.poiSearchNearBy(tvAdr.getText().toString(), geoPoint, 5000);
        //			GeoPoint geoPoint=new GeoPoint(39904965, 116327764);
        //			mkSearch.reverseGeocode(geoPoint);
        break;
      case R.id.btnLine:
        mapView.getOverlays().clear(); // 清除公交站点的标识
        EditText etLine = (EditText) findViewById(R.id.etLine);
        mkSearch.poiSearchInCity("北京", etLine.getText().toString());
        //			EditText etadd=(EditText) findViewById(R.id.etAddress);
        //			mkSearch.geocode("北京", etadd.getText().toString());
        break;

      default:
        break;
    }
  }
Beispiel #3
0
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.poisearch);

    BMapApiDemoApp app = (BMapApiDemoApp) this.getApplication();
    if (app.mBMapMan == null) {
      app.mBMapMan = new BMapManager(getApplication());
      app.mBMapMan.init(app.mStrKey, new BMapApiDemoApp.MyGeneralListener());
    }
    app.mBMapMan.start();
    // 如果使用地图SDK,请初始化地图Activity
    super.initMapActivity(app.mBMapMan);

    mMapView = (MapView) findViewById(R.id.bmapView);
    mMapView.setBuiltInZoomControls(true);
    // 设置在缩放动画过程中也显示overlay,默认为不绘制
    mMapView.setDrawOverlayWhenZooming(true);

    mBtnSearch = (Button) findViewById(R.id.search);

    OnClickListener clickListener =
        new OnClickListener() {
          public void onClick(View v) {
            SearchButtonProcess(v);
          }
        };
    mBtnSearch.setOnClickListener(clickListener);
  }
 @Override
 public void onGetAddrResult(MKAddrInfo info, int arg1) {
   // TODO Auto-generated method stub
   if (null != info && null != info.strAddr && !info.strAddr.equals("")) {
     Toast.makeText(mMapView.getContext(), info.strAddr, Toast.LENGTH_SHORT);
   } else {
     Toast.makeText(mMapView.getContext(), "未找到相关地址", Toast.LENGTH_SHORT);
   }
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mapView = (MapView) findViewById(R.id.bmapview);
    mbtnAdress = (Button) findViewById(R.id.btnAddress);
    mbtnAdress.setOnClickListener(this);
    mbtnLine = (Button) findViewById(R.id.btnLine);
    mbtnLine.setOnClickListener(this);
    bMapManager = new BMapManager(this);
    bMapManager.init(
        key,
        new MKGeneralListener() {

          @Override
          public void onGetPermissionState(int arg0) {
            // TODO Auto-generated method stub
            if (arg0 == 300) {
              Toast.makeText(MainActivity.this, "输入的key有误", 1);
            }
          }

          @Override
          public void onGetNetworkState(int arg0) {}
        });
    bMapManager.start();
    initMapActivity(bMapManager);
    mapView.setBuiltInZoomControls(true); // 设置中心点
    mkSearch = new MKSearch();
    mkSearch.init(bMapManager, new MySearchListener(this, mapView));
  }
 private void toCaricoCenter() {
   GeoPoint carGeoPoint = mApplication.getCarPosition().getGps();
   if (carGeoPoint != null) {
     mMapView.getController().setCenter(carGeoPoint);
   } else {
     toPointCenter();
   }
 }
 // 居中显示车辆位置或当前位
 private void toPointCenter() {
   Location location = GlobalApplication.getLocation();
   if (location != null) {
     GeoPoint geopoint =
         new GeoPoint((int) (location.getLatitude() * 1e6), (int) (location.getLongitude() * 1e6));
     mMapView.getController().setCenter(geopoint);
   }
 }
 public void hideAllBalloons() {
   if (!isInflating) {
     List<Overlay> mapOverlays = mapView.getOverlays();
     if (mapOverlays.size() > 1) {
       hideOtherBalloons(mapOverlays);
     }
     hideBalloon();
   }
 }
  protected void onHandlerSuccess(Object obj) {
    mActionBar.setProgressBarVisibility(View.GONE);
    if (obj != null) {
      @SuppressWarnings("unchecked")
      List<GPSInfo> lstWgs84HashMap = (List<GPSInfo>) obj;
      if (lstWgs84HashMap.size() > 0) { // 至少得有一个点嘛(第一个,最后一个有没有可能一样呢?有的)
        showMapViewRoutes(lstWgs84HashMap);
      } else {
        ToastShow.show(mPathActivity, R.string.datetime_toast_nodata);

        if (mMapView.getOverlays().contains(mRoutesOverlay)) {
          mMapView.getOverlays().remove(mRoutesOverlay);
          // mRoutesOverlay.onDestroy();
          mRoutesOverlay = null;
        }
        // if (mMapView.getOverlays().contains(mMovingOverlay)) {
        // mMapView.getOverlays().remove(mMovingOverlay);
        // mMovingOverlay.onDestroy();
        // mMovingOverlay = null;
        // }
      }
    }
  }
  private void checkInitMap() {
    if (mMapView == null) {
      mMapView = (MapView) findViewById(R.id.path_mapview);
      // 设置是否启用内置的缩放控件
      mMapView.setBuiltInZoomControls(true);
      // 设置在缩放动画过程中也显示overlay,默认为不绘制
      mMapView.setDrawOverlayWhenZooming(true);
      // mMapView.getOverlays().clear();

      // 添加定位图层
      mMxLocationOverlay = new MxLocationOverlay(mPathActivity, mMapView);
      mMxLocationOverlay.setOnOverlayEventListener(this);
      mMapView.getOverlays().add(mMxLocationOverlay);

      // 添加汽车图层
      mCaricoOverlay = new BitmapOverlay(mPathActivity, mMapView);
      mCaricoOverlay.setBitmap("rmct_routes_car.png");
      mMapView.getOverlays().add(mCaricoOverlay);

      mBtnBegTime = (Button) findViewById(R.id.path_begtime);
      mBtnEndTime = (Button) findViewById(R.id.path_endtime);
      mBtnBegTime.setOnClickListener(this);
      mBtnEndTime.setOnClickListener(this);

      mActionBar = (ActionBar) findViewById(R.id.path_actionbar);
      mActionBar.setRootView(findViewById(R.id.path_main));
      mViewback = mActionBar.showBackButton();
      mViewback.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              PathActivity.this.finish();
            }
          });
    }
  }
  public void draw(Canvas canvas, MapView mapView, boolean shadow) {
    // 投影,用于屏幕像素点坐标系统与地球经纬度点坐标系统的转换
    Projection projection = mapView.getProjection();
    for (int index = size() - 1; index >= 0; index--) {
      OverlayItem overlayItem = this.getItem(index);
      String title = overlayItem.getTitle();
      Point point = projection.toPixels(overlayItem.getPoint(), null);

      Paint painttext = new Paint();
      painttext.setColor(Color.BLACK);
      painttext.setTextSize(15);
      canvas.drawText(title, point.x - 30, point.y - 25, painttext);
    }

    super.draw(canvas, mapView, shadow);
    boundCenterBottom(marker);
  }
  @Override
  public void draw(Canvas canvas, MapView mapView, boolean shadow) {
    super.draw(canvas, mapView, shadow);
    boundCenterBottom(marker);

    Projection projection = mapView.getProjection();
    for (int index = size() - 1; index >= 0; index--) {
      OverlayItem overLayItem = getItem(index);
      @SuppressWarnings("unused")
      String title = overLayItem.getTitle();
      Point point = projection.toPixels(overLayItem.getPoint(), null);

      //			Hide Text
      /*Paint paintText = new Paint(Paint.ANTI_ALIAS_FLAG|Paint.DEV_KERN_TEXT_FLAG);
      paintText.setTypeface(Typeface.DEFAULT_BOLD);
      paintText.setFakeBoldText(true);
      paintText.setColor(Color.BLACK);
      paintText.setTextSize(16f);
      canvas.drawText(title, point.x-15, point.y+18, paintText); */

      // Draw number
      if (isShowNumber) {
        //				Point markStartPoint = getMarkerStartPoint(point);
        Paint numberPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);
        numberPaint.setColor(Color.WHITE);
        numberPaint.setTypeface(Typeface.DEFAULT_BOLD);

        int number = index + 1;
        if (number / 10 == 0) {
          numberPaint.setTextSize(19f);
          canvas.drawText(String.valueOf(number), point.x - 5, point.y - 26, numberPaint);
        } else {
          numberPaint.setTextSize(17f);
          canvas.drawText(String.valueOf(number), point.x - 10, point.y - 26, numberPaint);
        }
      }
    }
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mBMapMan = new BMapManager(getApplication());
    mBMapMan.init("C852FAE280E276186DE82EB547721866666283B0", null);
    super.initMapActivity(mBMapMan);

    mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);

    mapOverlays = mapView.getOverlays();

    // first overlay
    drawable = getResources().getDrawable(R.drawable.marker);
    itemizedOverlay = new CustomItemizedOverlay<CustomOverlayItem>(drawable, mapView);

    GeoPoint point = new GeoPoint((int) (39.90923 * 1E6), (int) (116.397428 * 1E6));
    CustomOverlayItem overlayItem =
        new CustomOverlayItem(
            point,
            "Tomorrow Never Dies (1997)",
            "(M gives Bond his mission in Daimler car)",
            "http://ia.media-imdb.com/images/M/MV5BMTM1MTk2ODQxNV5BMl5BanBnXkFtZTcwOTY5MDg0NA@@._V1._SX40_CR0,0,40,54_.jpg");
    itemizedOverlay.addOverlay(overlayItem);

    GeoPoint point2 = new GeoPoint((int) (39.9022 * 1E6), (int) (116.3922 * 1E6));
    CustomOverlayItem overlayItem2 =
        new CustomOverlayItem(
            point2,
            "GoldenEye (1995)",
            "(Interiors Russian defence ministry council chambers in St Petersburg)",
            "http://ia.media-imdb.com/images/M/MV5BMzk2OTg4MTk1NF5BMl5BanBnXkFtZTcwNjExNTgzNA@@._V1._SX40_CR0,0,40,54_.jpg");
    itemizedOverlay.addOverlay(overlayItem2);

    mapOverlays.add(itemizedOverlay);

    // second overlay
    drawable2 = getResources().getDrawable(R.drawable.marker2);
    itemizedOverlay2 = new CustomItemizedOverlay<CustomOverlayItem>(drawable2, mapView);

    GeoPoint point3 = new GeoPoint((int) (39.917723 * 1E6), (int) (116.3722 * 1E6));
    CustomOverlayItem overlayItem3 =
        new CustomOverlayItem(point3, "Sliding Doors (1998)", "(interiors)", null);
    itemizedOverlay2.addOverlay(overlayItem3);

    GeoPoint point4 = new GeoPoint((int) (51.51738 * 1E6), (int) (-0.08186 * 1E6));
    CustomOverlayItem overlayItem4 =
        new CustomOverlayItem(
            point4,
            "Mission: Impossible (1996)",
            "(Ethan & Jim cafe meeting)",
            "http://ia.media-imdb.com/images/M/MV5BMjAyNjk5Njk0MV5BMl5BanBnXkFtZTcwOTA4MjIyMQ@@._V1._SX40_CR0,0,40,54_.jpg");
    itemizedOverlay2.addOverlay(overlayItem4);

    mapOverlays.add(itemizedOverlay2);

    final MapController mc = mapView.getController();
    mc.animateTo(point2);
    mc.setZoom(16);
  }
 @Override
 public void draw(Canvas canvas, MapView mapView, boolean shadow) {
   // 在天安门的位置绘制一个String
   Point point = mapView.getProjection().toPixels(geoPoint, null);
   canvas.drawText("★这里是天安门", point.x, point.y, paint);
 }
 /**
  * Create a new BalloonItemizedOverlay
  *
  * @param defaultMarker - A bounded Drawable to be drawn on the map for each item in the overlay.
  * @param mapView - The view upon which the overlay items are to be drawn.
  */
 public BalloonItemizedOverlay(Drawable defaultMarker, MapView mapView) {
   super(defaultMarker);
   this.mapView = mapView;
   viewOffset = 0;
   mc = mapView.getController();
 }
  /**
   * Creates and displays the balloon overlay by recycling the current balloon or by inflating it
   * from xml.
   *
   * @return true if the balloon was recycled false otherwise
   */
  private boolean createAndDisplayBalloonOverlay() {
    boolean isRecycled;
    if (balloonView == null) {
      balloonView = createBalloonOverlayView();
      clickRegion = balloonView.findViewById(R.id.balloon_inner_layout);
      clickRegion.setOnTouchListener(createBalloonTouchListener());
      closeRegion = balloonView.findViewById(R.id.balloon_close);
      if (closeRegion != null) {
        if (!showClose) {
          closeRegion.setVisibility(View.GONE);
        } else {
          closeRegion.setOnClickListener(
              new OnClickListener() {
                @Override
                public void onClick(View v) {
                  hideBalloon();
                }
              });
        }
      }
      if (showDisclosure && !showClose) {
        View v = balloonView.findViewById(R.id.balloon_disclosure);
        if (v != null) {
          v.setVisibility(View.VISIBLE);
        }
      }
      isRecycled = false;
    } else {
      isRecycled = true;
    }

    balloonView.setVisibility(View.GONE);

    List<Overlay> mapOverlays = mapView.getOverlays();
    if (mapOverlays.size() > 1) {
      hideOtherBalloons(mapOverlays);
    }

    if (currentFocusedItem != null) {
      balloonView.setData(currentFocusedItem);
    }

    GeoPoint point = currentFocusedItem.getPoint();
    MapView.LayoutParams params =
        new MapView.LayoutParams(
            LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT,
            point,
            MapView.LayoutParams.BOTTOM_CENTER);
    params.mode = MapView.LayoutParams.MODE_MAP;

    balloonView.setVisibility(View.VISIBLE);

    if (isRecycled) {
      balloonView.setLayoutParams(params);
    } else {
      mapView.addView(balloonView, params);
    }

    return isRecycled;
  }